Principle:Ollama Ollama Architecture Detection
| Knowledge Sources | |
|---|---|
| Domains | Model_Architecture, Format_Conversion |
| Last Updated | 2026-02-14 00:00 GMT |
Overview
A metadata-driven model architecture detection mechanism that identifies the model family from HuggingFace config.json and selects the appropriate format converter.
Description
Architecture Detection is the first step in model format conversion. HuggingFace models include a config.json file with an architectures field that identifies the model family (e.g., "LlamaForCausalLM", "GemmaForCausalLM", "Qwen2ForCausalLM"). This field is used to dispatch to the correct converter that knows the architecture-specific tensor name mappings, weight layouts, and metadata keys.
The detection supports 25+ architecture families including LLaMA, Gemma, Qwen2, DeepSeek V2/V3, Mistral, Phi-3, BERT, and others.
Usage
Use this principle when building a multi-architecture model converter that must automatically detect and handle different model families from a common input format.
Theoretical Basis
The detection algorithm:
- Read config.json: Parse the JSON configuration file from the model directory.
- Extract architectures: Read the "architectures" array field.
- Lookup converter: Match the architecture string to a registered converter implementation.
- Fallback: If no exact match, attempt to infer from other config fields or fail with an informative error.