import torch | |
model_path = r'C:\Users\marco\financebert\model.safetensors' | |
try: | |
# Try loading the model directly | |
model = torch.load(model_path) | |
print("Model loaded successfully:", model) | |
except Exception as e: | |
print("Failed to load the model directly:", str(e)) | |
# If direct loading fails, consider that the file might need handling of specific layers or configs | |
try: | |
# Sometimes models are wrapped in a dictionary or other structures | |
model_data = torch.load(model_path, map_location=torch.device('cpu')) | |
print("Model data loaded, attempt to extract model:", model_data.keys()) | |
# If model is under a specific key or requires further processing | |
if 'model' in model_data: | |
model = model_data['model'] | |
print("Extracted model from dictionary:", model) | |
else: | |
print("Check the keys in model_data and adjust accordingly") | |
except Exception as e2: | |
print("Failed in adjusted loading approach:", str(e2)) | |