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 fordtype(torch_dtypein older files): 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.
The keys page lists the keys every configuration
writes, with the Llama configuration as an example.
Not described
config.json has no fixed schema: each model family defines its own keys in
its configuration class. The keys page gives the common ones and LlamaConfig as an
example.
Known, not yet covered
- Reference: the keys of the several hundred other families'
configuration classes in
transformers(BERT, GPT-2, Mistral and T5 are added on the keys page), and the fields ofcontinuous_batching_configin the generation config. The way the file is written and the generation_config.json keys are now described. - Viewer: not re-audited in this pass.
Unknown
- Reference: a complete list of keys: the set is open-ended, since any project may add a family.
Also used for
- Browser extension manifest – The JSON manifest of a browser extension: its name, permissions and scripts.
- GeoJSON – Map points, lines and areas with properties, written as JSON.
- Hugging Face tokenizer (tokenizer.json) – tokenizer.json: a language model’s vocabulary and tokenising rules.
- JSON Schema – A JSON document that describes and validates other JSON documents.
- JavaScript Object Notation – Text format for objects, arrays, strings, numbers and booleans.
- Lottie animation – Vector animations as JSON, exported from After Effects and played in apps and web pages.
- Visual Studio Code settings – VS Code’s settings.json: dotted setting IDs in JSON with comments.
- jCal: iCalendar in JSON – iCalendar as JSON: events, to-dos and time zones as nested arrays.
- jCard: vCard in JSON – vCard 4.0 contacts as JSON: names, numbers and addresses as arrays.
- npm package manifest (package.json) – A JavaScript package’s name, version, scripts and dependencies, in JSON.
Links
Software
- Hugging Face Transformers – reads it with
AutoConfigbefore loading the weights (Python) - Hugging Face – model hub that shows each model’s files (web)
Reference
- Configuration – the Transformers documentation for config classes and their keys