File size: 708 Bytes
bbdec87
 
6a1cd8b
bbdec87
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import joblib
import torch
from huggingface_hub import hf_hub_download

# Define a custom load function to force CPU loading
def custom_torch_load(f, *args, **kwargs):
    if 'map_location' not in kwargs:
        kwargs['map_location'] = torch.device("cpu")
    return torch_load_backup(f, *args, **kwargs)

# Monkey patch torch.load inside joblib.load
torch_load_backup = torch.load  # Backup the original function
torch.load = custom_torch_load  # Override with CPU-only loading

# Load the model
topic_model = joblib.load("bertopic_model_max_compressed.joblib")

# Restore the original torch.load function
torch.load = torch_load_backup

# Verify loading success
print("Model loaded successfully on CPU")