Introduction
A weights file such as safetensors holds numbers,
not the shape of the network they belong to. In a model folder on
Hugging Face, that information is in
config.json: which architecture the model uses and how big each part of it
is. Transformers reads it first to
build an empty model of the right shape, then fills it with the weights. Other programs
read it too, for example to convert a model to GGUF.
A model folder often also has generation_config.json, with default
settings for generating text, and the tokenizer files described under
Hugging Face tokenizer.
Structure
The file is one JSON object. The keys depend on the architecture, but a language model’s config usually includes:
architectures: the model class to build, such asLlamaForCausalLMmodel_type: the family, such asllama,bertormistralvocab_size,hidden_size,intermediate_size,num_hidden_layersandnum_attention_heads: the sizesmax_position_embeddings: the longest input it was built fortorch_dtype: the number type of the saved weights, such asbfloat16transformers_version: the version that wrote the file
Models whose code is not part of Transformers add an auto_map key naming
Python files in the same folder, which run only when the user allows remote code.
Also used for
- GeoJSON .json
- Hugging Face tokenizer (tokenizer.json) .json
- JSON Schema .json
- JavaScript Object Notation .json
- Lottie animation .json
- Visual Studio Code settings .json
- npm package manifest (package.json) .json
Links
Software
- Hugging Face Transformers, which reads it with
AutoConfig - Hugging Face, which shows each model’s files
Reference
- Configuration, Transformers documentation