diegosouzapw/OmniRoute · error · Error
Unexpected safetensors shape
Error message
Unexpected safetensors shape: ${JSON.stringify(shape)} What it means
The parsed model.safetensors tensor shape (JSON-serialized into the message) does not match the 2-D [vocab_size, hidden_dim] embedding matrix the static (local) embedding engine expects. The downloaded artifact is corrupted, truncated, or from a different model than the vocab — a version mismatch between the cached vocab.json and model.safetensors.
Solutions
- Re-download the correct model revision — upstream changed the artifact layout
- Verify dim/vocabSize in the config match the downloaded files
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at src/lib/memory/embedding/staticPotion.ts:123 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of diegosouzapw/OmniRoute@a179ffed5b (2026-08-25).
Data as JSON: /api/errors/6bad31a9505900db.
Report an issue: GitHub.
Appendix: source
Thrown at src/lib/memory/embedding/staticPotion.ts:123
const modelPath = path.join(modelDir, "model.safetensors");
const tokenizerPath = path.join(modelDir, "tokenizer.json");
await Promise.all([
ensureFile(vocabPath, `${hfBase}/vocab.json`),
ensureFile(modelPath, `${hfBase}/model.safetensors`),
ensureFile(tokenizerPath, `${hfBase}/tokenizer.json`),
]);
// Load vocab
const vocabRaw = await fs.readFile(vocabPath, "utf8");
const vocab = JSON.parse(vocabRaw) as Record<string, number>;
// Load matrix from safetensors
const modelBuf = await fs.readFile(modelPath);
const { matrix, shape } = parseSafetensors(modelBuf);
if (shape.length < 2) {
throw new Error(`Unexpected safetensors shape: ${JSON.stringify(shape)}`);
}
const vocabSize = shape[0];
const dim = shape[1];
const unkIdx = vocab["[UNK]"] ?? 0;
return { vocab, matrix, dim, vocabSize, unkIdx };
}
export function getOrLoadModel(): Promise<PotionModel> {
if (_model) return Promise.resolve(_model);
if (_loading) return _loading;
_loading = loadModel().then((m) => {
_model = m;
_loading = null;
return m;
});
return _loading;View on GitHub (pinned to a179ffed5b)