Some links on this page are affiliate links: if you buy through them we may earn a commission, at no extra cost to you.
The usual cause is not simply “no internet.” The loader either cannot find every required file locally, the path is wrong, the checkpoint is incomplete or incompatible, or the code is still trying to resolve a missing file from the Hub. For Hugging Face Transformers, load a complete model directory with an absolute path, local_files_only=True, and—when appropriate—HF_HUB_OFFLINE=1. For a raw PyTorch checkpoint, use torch.load() with the correct file path, recreate the original architecture, and restore its state_dict.
An OSError is only the outer exception type. The full error message and the loader that raised it determine the real fix.
First identify the loader
Find the line that fails:
from_pretrained(...): usually a Hugging Face Transformers, Diffusers, or Sentence-Transformers local-directory issue.torch.load(...): a raw PyTorch serialization or checkpoint issue.pipeline(...): potentially loads a model, tokenizer, configuration, processor, and other assets.torch.hub.load(...): uses PyTorch Hub’s own repository and cache behavior; see the PyTorch Hub documentation.
Do not report only “I got an OSError.” Copy the complete traceback, especially its final 10–20 lines.
Do these 3 things before closing this tab:
1Clear out junk files and repair common Windows errors2Scan for outdated or missing drivers - takes under a minute3Repair Windows errors before they cause bigger problems| Error pattern | Likely cause | First check |
|---|---|---|
We couldn't connect to https://huggingface.co |
A required file is missing or the input was treated as a Hub identifier. | Use local_files_only=True and inspect the directory. |
not the path to a directory containing config.json |
Wrong path, a file was supplied instead of a directory, or the export is incomplete. | Print the resolved path and list its files. |
Unable to load weights from pytorch checkpoint file |
Corrupt, truncated, incompatible, or incorrectly selected checkpoint. | Check its size, hash, format, and loader. |
FileNotFoundError |
Path, filename, mount, permissions, or case-sensitivity problem. | Verify the path from inside the running environment. |
Missing key(s) or Unexpected key(s) |
The state dictionary does not match the instantiated architecture. | Recreate the exact training model. |
| CUDA-related loading error | The checkpoint targets CUDA but the current machine does not have a compatible device. | Use map_location="cpu". |
Fix a local Hugging Face Transformers model
Transformers’ from_pretrained() accepts a Hub repository ID or a local directory. A local model directory normally needs a configuration file, compatible weights, and—if tokenization happens locally—the tokenizer assets. The Transformers model documentation describes local loading and saved model files.
#1 Best Overall
- Get NVMe solid state performance with up to 1050MB/s read and 1000MB/s write speeds in a portable, high-capacity drive(1) (Based on internal testing; performance may be lower depending on host device & other factors. 1MB=1,000,000 bytes.)
- Up to 3-meter drop protection and IP65 water and dust resistance mean this tough drive can take a beating(3) (Previously rated for 2-meter drop protection and IP55 rating. Now qualified for the higher, stated specs.)
- Use the handy carabiner loop to secure it to your belt loop or backpack for extra peace of mind.
- Help keep private content private with the included password protection featuring 256‐bit AES hardware encryption.(3)
- Easily manage files and automatically free up space with the SanDisk Memory Zone app.(5). Non-Operating Temperature -20°C to 85°C
1. Resolve and verify the path
Use an absolute path while diagnosing:
from pathlib import Path
model_dir = Path("/models/my-model").resolve()
print("Path:", model_dir)
print("Exists:", model_dir.exists())
print("Directory:", model_dir.is_dir())
if model_dir.exists() and model_dir.is_dir():
for path in sorted(model_dir.iterdir()):
print(path.name)
On Windows, use a raw string to avoid backslash escape problems:
from pathlib import Path
model_dir = Path(r"C:modelsmy-model").resolve()
Check that you did not pass the parent directory, a single .bin or .safetensors file, a misspelled path, or a relative path whose meaning changes with the current working directory. Also verify read permission and, in containers, that the directory is mounted inside the container.
2. Check the expected files
A typical directory may contain:
config.json
model.safetensors
# or: pytorch_model.bin
Other files depend on the model:
tokenizer_config.json
tokenizer.json
special_tokens_map.json
vocab.json
merges.txt
sentencepiece.bpe.model
generation_config.json
preprocessor_config.json
model.safetensors.index.json
model-00001-of-00003.safetensors
model-00002-of-00003.safetensors
model-00003-of-00003.safetensors
There is no universal file list. A sharded model requires its index and every shard referenced by that index. Copying only the first weight file is insufficient.
Free tools Windows power users keep installed
One-click scans. No signup required.
from pathlib import Path
model_dir = Path("/models/my-model")
print("Configuration:", (model_dir / "config.json").is_file())
print("Weight-related files:")
for path in sorted(model_dir.iterdir()):
if (path.name.endswith((".safetensors", ".bin", ".pt", ".pth"))
or path.name.endswith(".index.json")):
print(" -", path.name)
3. Force the load to remain local
Set the environment variable before starting the application and pass the per-call option:
HF_HUB_OFFLINE=1 python app.py
Windows Command Prompt:
set HF_HUB_OFFLINE=1
python app.py
PowerShell:
$env:HF_HUB_OFFLINE="1"
python app.py
Then load the tokenizer and model explicitly:
from pathlib import Path
from transformers import AutoTokenizer, AutoModelForSequenceClassification
model_dir = Path("/models/my-classifier").resolve()
if not model_dir.is_dir():
raise FileNotFoundError(f"Missing model directory: {model_dir}")
if not (model_dir / "config.json").is_file():
raise FileNotFoundError(f"Missing config.json in: {model_dir}")
tokenizer = AutoTokenizer.from_pretrained(
str(model_dir),
local_files_only=True,
)
model = AutoModelForSequenceClassification.from_pretrained(
str(model_dir),
local_files_only=True,
)
model.eval()
HF_HUB_OFFLINE=1 prevents Hugging Face Hub HTTP calls, while local_files_only=True tells that loading operation to use local files. Neither option downloads missing files; offline mode makes an incomplete export fail more clearly. See the Transformers offline-mode guidance.
Rank #2
- Solid state performance with up to 800MB/s read speeds in a portable drive. (Based on internal testing; performance may be lower depending on host device, interface, usage conditions and other factors. 1MB=1,000,000 bytes.)
- Back up your content and memories on a storage solution that fits seamlessly into your mobile lifestyle.
- Take it with you on your adventures—up to two-meter drop protection means this durable drive can take a beating. (Based on internal testing.)
- Secure it to your belt loop or backpack for extra peace of mind thanks to the tough rubber hook.
- From Sandisk, a brand professional photographers trust to take on assignments.
4. Do not forget the tokenizer
Model weights can be valid while the application still fails because the tokenizer is absent. Tokenizer assets may include tokenizer.json, tokenizer_config.json, special_tokens_map.json, vocab.txt, vocab.json, merges.txt, or a SentencePiece model. A model-only workflow with already-tokenized inputs may not need them, but a normal text pipeline does.
from transformers import pipeline
classifier = pipeline(
"sentiment-analysis",
model="/models/my-classifier",
tokenizer="/models/my-classifier",
local_files_only=True,
)
print(classifier("The local model loaded successfully."))
Export the model correctly before going offline
“The model is on disk” should mean that every file required by the application is on disk—not merely one downloaded weight file.
Download a complete repository while connected
from huggingface_hub import snapshot_download
snapshot_download(
repo_id="org/model-name",
repo_type="model",
local_dir="/transfer/model-name",
)
Transfer the resulting directory to the disconnected machine and load it by path. Private or gated repositories must be authenticated during the connected download phase; the offline system should not be expected to fetch missing files later.
Materialize a clean export
If you have already loaded the model on a connected machine, save both components:
tokenizer.save_pretrained("/transfer/my-model")
model.save_pretrained("/transfer/my-model")
This is usually easier to validate than manually copying an arbitrary cache. Hugging Face caches contain snapshots, blobs, references, and sometimes symlinks. The Hub cache documentation explains that layout.
Rank #3
- Easily store and access 2TB to content on the go with the Seagate Portable Drive, a USB external hard drive
- Designed to work with Windows or Mac computers, this external hard drive makes backup a snap just drag and drop
- To get set up, connect the portable hard drive to a computer for automatic recognition no software required
- This USB drive provides plug and play simplicity with the included 18 inch USB 3.0 cable
- The available storage capacity may vary.
If you must use the cache, point the loader at the specific snapshot directory, such as:
Recommended Free Tools
.../huggingface/hub/models--org--model/snapshots/<revision>/
Do not point blindly at the cache root or edit cache internals. Cache locations can be changed with variables including HF_HUB_CACHE and HF_HOME; see the cache setup documentation.
Check for incomplete or corrupted files
A file can exist and still be unusable. Inspect sizes and temporary files:
from pathlib import Path
for path in Path("/models/my-model").rglob("*"):
if path.is_file():
print(path, path.stat().st_size, "bytes")
Look for zero-byte or suspiciously small weights, temporary download extensions, missing shards, broken symlinks, and an index that references filenames not present locally. For higher-assurance transfers, compare hashes on both machines:
sha256sum model.safetensors
PowerShell:
Get-FileHash .model.safetensors -Algorithm SHA256
For a sharded model, verify every shard, not just the first file.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
Rank #4
- NEARLY 2X FASTER THAN OUR PREVIOUS GENERATION(8) – move 1,000 high-res photos in under 60 seconds(6) with up to 2000MB/s transfer speeds(2).
- IP65 RATING AND UP TO 3M DROP PROTECTION(3) – protects against spills and drops.
- POCKET-SIZED – fits easily in pockets and small bags.
- SPACE TO OWN YOUR AI CONTENT – speed and capacity to download your high-res clips and photo edits.
- 256-BIT AES ENCRYPTION(4) – helps keep private files secure with password protection.
Fix raw PyTorch checkpoint loading
torch.load() deserializes a PyTorch file; it does not automatically know which model architecture to construct. If the file was created with torch.save(model.state_dict(), ...), instantiate the architecture first:
import torch
from my_project.model import MyModel
model = MyModel(num_classes=10)
state_dict = torch.load(
"/models/model.pt",
map_location="cpu",
weights_only=True,
)
model.load_state_dict(state_dict)
model.eval()
PyTorch documents map_location="cpu" for remapping tensors to the CPU and weights_only for restricted loading of tensors, primitive types, dictionaries, and approved safe globals in compatible workflows. See the torch.load() documentation.
Checkpoints often wrap the state dictionary:
checkpoint = torch.load(
"/models/checkpoint.pt",
map_location="cpu",
weights_only=True,
)
state_dict = checkpoint.get(
"model_state_dict",
checkpoint.get("state_dict")
)
if state_dict is None:
raise KeyError(
"Checkpoint has no model_state_dict or state_dict key"
)
model.load_state_dict(state_dict)
model.eval()
The key name is application-specific. Other entries may contain optimizer state, epoch numbers, or training metadata.
A direct call such as torch.load("model.pt") can fail or be unusable when the file contains only weights, the original Python class is unavailable, the checkpoint was saved on CUDA, the file is not actually a PyTorch pickle, or the file is corrupted. A checkpoint saved with torch.save(model, ...) may require the original class and import path and is less portable.
PC Slower Than It Used to Be?
A free scan shows the junk files, broken settings and background clutter dragging Windows down - then fixes them in one click.Free scan · Windows 10 & 11Crashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minuteFormat, dependency, and hardware issues
Safetensors is not a PyTorch pickle
Do not pass a .safetensors file to torch.load() as though it were a standard PyTorch checkpoint. Use the Transformers loader or a compatible safetensors loader. Safetensors is designed for model weights and avoids the traditional pickle-based object-deserialization model; support still depends on the library and checkpoint structure. The Transformers documentation provides the relevant loading context.
Best Value
- Easily store and access 5TB of content on the go with the Seagate portable drive, a USB external hard Drive
- Designed to work with Windows or Mac computers, this external hard drive makes backup a snap just drag and drop
- To get set up, connect the portable hard drive to a computer for automatic recognition software required
- This USB drive provides plug and play simplicity with the included 18 inch USB 3.0 cable
- The available storage capacity may vary.
Version and backend mismatches
Record the environment when the standard fixes fail:
python --version
pip show torch transformers huggingface-hub safetensors
Quantized models may need a particular quantization backend and compatible CPU or GPU support. A missing package cannot be repaired with an ordinary online pip install on an air-gapped machine unless wheels are already available locally or through an internal package repository.
Likewise, successful loading does not guarantee enough RAM or VRAM for inference. A CPU fallback may open the checkpoint but still run out of memory during model construction or execution.
Common environment traps
Relative paths
./model is relative to the process’s current working directory, not necessarily the Python file’s directory:
import os
print(os.getcwd())
When suitable for your application, derive the path from the script location:
from pathlib import Path
model_dir = Path(__file__).resolve().parent / "model"
Docker and virtual machines
A model on the host is not automatically available inside a container. Check from inside the running container:
docker exec -it <container> sh
ls -la /models/my-model
A typical bind mount is:
docker run --rm
-v "$PWD/models:/models:ro"
my-image
Exact syntax varies by operating system and runtime. Also check the container user’s read permission and filename case.
The Tool Desk
Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →Custom model code
Some repositories require Python modeling code in addition to configuration and weights. That code and all dependencies must be transferred in advance. If a model specifically requires trust_remote_code=True, review and transfer the code deliberately; do not enable arbitrary remote code execution as a generic workaround.
Quick Recap
Security precautions
- Load only trusted checkpoint files.
- Prefer safetensors where the model and loader support it.
- Use
weights_only=Truefor compatible state-dictionary workflows. - Avoid disabling restricted loading for an unknown file.
- Review custom code before using
trust_remote_code=True. - Validate checksums before moving artifacts into production.
Final offline diagnostic checklist
- Identify whether the failing API is
from_pretrained,torch.load,pipeline,torch.hub, or custom code. - Print the absolute path and confirm it exists.
- Confirm a
from_pretrainedinput is a directory. - Confirm
config.json, compatible weights, and tokenizer or processor files are present. - For sharded models, confirm the index and every referenced shard exist.
- Check file sizes, symlinks, hashes, and read permissions.
- Use
local_files_only=Trueand setHF_HUB_OFFLINE=1. - For raw PyTorch, recreate the exact architecture, use
map_location="cpu"when needed, and inspect checkpoint keys. - Check Python, package, quantization-backend, and device compatibility.
- Test in a genuinely disconnected environment and preserve the complete traceback.
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

