config.json is a Transformers configuration object written as JSON;
each model family defines its own class and keys. This page follows the base class
in configuration_utils.py,
the file names in utils/constants.py, dynamic_module_utils.py
for auto_map, and
configuration_llama.py
as an example, all read 2026-11-12. Loading a config builds the model’s shape; it does
not load any weights.
Keys from the base class
| Key | Meaning |
|---|---|
model_type | The family identifier, such as llama; written into the JSON from the class and used by AutoConfig to pick the class back. |
transformers_version | The Transformers version that wrote the file. |
architectures | Model classes that can be used with the saved weights. |
dtype | The data type of the weights, written as a name such as float16. Older files call it torch_dtype; Transformers still reads that name but calls it deprecated. |
id2label, label2id, problem_type | Class labels and the kind of classification (regression, single_label_classification or multi_label_classification). |
is_encoder_decoder, output_hidden_states, return_dict, chunk_size_feed_forward | General model behaviour. |
auto_map | For models whose code is not part of Transformers: maps an Auto class to the custom class that implements it. |
The base class lists vocab_size, hidden_size,
num_attention_heads and num_hidden_layers as common
attributes of all subclasses, mapped through each class’s
attribute_map when a model names them differently. It also says that
putting text-generation settings in the model config is deprecated; they belong in
generation_config.json.
Example: LlamaConfig
model_type llama. Its keys and defaults:
| Key | Default |
|---|---|
vocab_size | 32000 |
hidden_size | 4096 |
intermediate_size | 11008 |
num_hidden_layers | 32 |
num_attention_heads | 32 |
num_key_value_heads | none |
head_dim | none |
hidden_act | silu |
max_position_embeddings | 2048 |
initializer_range | 0.02 |
rms_norm_eps | 1e-6 |
use_cache | true |
pad_token_id, bos_token_id, eos_token_id | none, 1, 2 |
pretraining_tp | 1 |
tie_word_embeddings | false |
rope_parameters | none |
attention_bias, mlp_bias | false |
attention_dropout | 0.0 |
How the file is written
From the main branch of configuration_utils.py (read 2026-11-13), where
the configuration base class, PreTrainedConfig, is now a Python dataclass
(fields keyword-only) with the class attributes listed below.
- Format:
config.json(CONFIG_NAME),json.dumps(…, indent=2, sort_keys=True)plus a final newline, written byto_json_file(…, use_diff=True). Keys are therefore in alphabetical order. Infinite and NaN floats are encoded specially before dumping. - Diff form: by default only values that differ from a fresh base
PreTrainedConfig()or from the family's class defaults are written, always withtransformers_version(the version that saved it) and themodel_type;_name_or_pathis dropped; aquantization_configis written as a dict; a torch dtype is written as its name (dict_dtype_to_str); nested configs (text_config,vision_configand the like, fromsub_configs_defaults) are diffed recursively and keep theirmodel_type. A value equal to its default can therefore be missing from a file and still be in effect. - Base keys (fields of the base class):
transformers_version,architectures,output_hidden_states(false),return_dict(true),dtype,chunk_size_feed_forward(0: feed-forward layers are not chunked),is_encoder_decoder(false),id2label,label2id,problem_type. Others the docstring and loader handle:output_attentions(false),name_or_path(not saved),num_labels(kept as 2 when there is noid2label; the JSON keys ofid2labelare strings turned into integers on load;problem_typesingle_label_classificationneeds more than one label),attn_implementation,experts_implementation,per_layer_config(a sparse map from layer index to the attributes that differ for that layer),tie_last_hidden_states,rope_parameters(legacyrope_scalingandrope_thetakeys are converted when a class hasrope_parameters). - Old name:
torch_dtypeis still read and used whendtypeis not set; the string is turned into atorchdtype object after loading. - Generation keys are dropped: keys that are defaults of
GenerationConfig(see below) are popped from the model config on load, so they do not survive there. - Class attributes, not in the JSON:
model_type,attribute_map(alias to real field name, for example GPT-2'shidden_sizeton_embd),base_model_tp_plan,base_model_pp_plan,base_model_ep_planandbase_model_fsdp_plan(parallelism plans for sub-modules, such aslayers.*.self_attn.q_proj: colwise),sub_configs_defaults,keys_to_ignore_at_inference(in GPT-2).
More families
Fields and defaults of four more configuration_*.py files of the same
repository (main branch, read 2026-11-13). Unlisted keys come from the base class.
model_type | Fields and defaults |
|---|---|
bert | vocab_size 30522, hidden_size 768, num_hidden_layers 12, num_attention_heads 12, intermediate_size 3072, hidden_act gelu, hidden_dropout_prob 0.1, attention_probs_dropout_prob 0.1, max_position_embeddings 512, type_vocab_size 2, initializer_range 0.02, layer_norm_eps 1e-12, pad_token_id 0, use_cache true, classifier_dropout none, is_decoder false, add_cross_attention false, bos_token_id none, eos_token_id none, tie_word_embeddings true. |
gpt2 | vocab_size 50257, n_positions 1024, n_embd 768, n_layer 12, n_head 12, n_inner none, activation_function gelu_new, resid_pdrop, embd_pdrop, attn_pdrop 0.1 each, layer_norm_epsilon 1e-5, initializer_range 0.02, summary_type cls_index, summary_use_proj true, summary_activation none, summary_proj_to_labels true, summary_first_dropout 0.1, scale_attn_weights true, use_cache true, bos_token_id and eos_token_id 50256, pad_token_id none, scale_attn_by_inverse_layer_idx false, reorder_and_upcast_attn false, add_cross_attention false, tie_word_embeddings true. attribute_map: hidden_size to n_embd, max_position_embeddings to n_positions, num_attention_heads to n_head, num_hidden_layers to n_layer. |
mistral | vocab_size 32000, hidden_size 4096, intermediate_size 14336, num_hidden_layers 32, num_attention_heads 32, num_key_value_heads 8, head_dim none, hidden_act silu, max_position_embeddings 4096 × 32, initializer_range 0.02, rms_norm_eps 1e-6, use_cache true, pad_token_id none, bos_token_id 1, eos_token_id 2, tie_word_embeddings false, rope_parameters none, sliding_window 4096, attention_dropout 0.0. |
t5 | vocab_size 32128, d_model 512, d_kv 64, d_ff 2048, num_layers 6, num_decoder_layers none, num_heads 8, relative_attention_num_buckets 32, relative_attention_max_distance 128, dropout_rate 0.1, layer_norm_epsilon 1e-6, initializer_factor 1.0, feed_forward_proj relu, is_encoder_decoder true, use_cache true, pad_token_id 0, eos_token_id 1, classifier_dropout 0.0, is_decoder false. attribute_map: hidden_size to d_model, num_attention_heads to num_heads, num_hidden_layers to num_layers, head_dim to d_kv. |
generation_config.json
From generation/configuration_utils.py (read 2026-11-13). The file holds the
attributes of GenerationConfig, written like the model config in diff form
(to_json_string(use_diff=True) with the metadata fields
_from_model_config, _commit_hash, _original_object_hash
and transformers_version available to drop). Every attribute is stored as
None unless given; when something unset is needed the library applies the
following defaults (_get_default_generation_params), which the model config's
reader also treats as generation keys to discard.
| Group | Keys (default when unset) |
|---|---|
| Length | max_length (20), max_new_tokens, min_length (0), min_new_tokens, early_stopping (false), max_time, stop_strings. |
| Strategy | do_sample (false), num_beams (1), use_mtp, low_memory, penalty_alpha, dola_layers, num_beam_groups (1), diversity_penalty (0.0), constraints, force_words_ids, prefill_chunk_size. |
| Cache | use_cache (true), cache_implementation (one of static, offloaded_static, dynamic, offloaded, quantized, or the deprecated sliding_window, hybrid, hybrid_chunked, offloaded_hybrid, offloaded_hybrid_chunked), cache_config, max_cache_len. |
| Sampling | temperature (1.0), top_k (50), top_p (1.0), min_p, top_h, typical_p (1.0), epsilon_cutoff (0.0), eta_cutoff (0.0). |
| Logit processing | repetition_penalty (1.0), encoder_repetition_penalty (1.0), length_penalty (1.0), no_repeat_ngram_size (0), encoder_no_repeat_ngram_size (0), bad_words_ids, renormalize_logits, forced_bos_token_id, forced_eos_token_id, remove_invalid_values (false), exponential_decay_length_penalty, suppress_tokens, begin_suppress_tokens, sequence_bias, token_healing, guidance_scale, watermarking_config. |
| Output | num_return_sequences (1), output_attentions, output_hidden_states, output_scores (false), output_logits, return_dict_in_generate (false). |
| Special tokens | pad_token_id, bos_token_id, eos_token_id, decoder_start_token_id. |
| Assisted generation | is_assistant, num_assistant_tokens (20), num_assistant_tokens_schedule (constant), assistant_confidence_threshold (0.4), prompt_lookup_num_tokens, max_matching_ngram_size, assistant_early_exit, assistant_lookbehind (10), target_lookbehind (10), assistant_ensemble_weight, speculation_type. |
| Execution | compile_config (CompileConfig: fullgraph false, dynamic, backend inductor, mode reduce-overhead, options), disable_compile, continuous_batching_config (a dataclass with many fields, from page_size 256 to block_size; not listed here). |
| Metadata | _from_model_config, transformers_version; unknown extra keys are kept as attributes. |