HuggingFaceConfig

Options & Configuration · AiDotNet.ModelLoading.Pretrained

A strongly-typed view over a Hugging Face decoder config.json (the LLaMA / Mistral / Qwen2 text-model family). Only the fields needed to reconstruct the architecture are read; unknown fields are ignored so newer configs still parse.

For Beginners

Every Hugging Face model ships a small config.json that describes its shape — how wide it is, how many layers, how many attention heads, and so on. This class turns that JSON into typed properties AiDotNet can build a matching model from.

Constructors

Constructor Summary
HuggingFaceConfig()

Properties

Property Summary
IReadOnlyList<string> Architectures { get; set; } The declared architecture classes, e.g.
bool TieWordEmbeddings { get; set; } Whether the LM head shares weights with the input embedding.
double RmsNormEps { get; set; } RMSNorm epsilon.
double RopeTheta { get; set; } RoPE base frequency (rope_theta).
double? AttnLogitSoftcapping { get; set; } Attention-logit soft-cap magnitude (Gemma-2 attn_logit_softcapping); null when absent.
double? FinalLogitSoftcapping { get; set; } Final-logit soft-cap magnitude (Gemma-2 final_logit_softcapping); null when absent.
double? LogitScale { get; set; } Logit multiplier (Cohere logit_scale); null when absent.
int HeadDim { get; set; } Per-head dimension.
int HiddenSize { get; set; } Model (residual stream) width — the embedding / hidden dimension.
int IntermediateSize { get; set; } Feed-forward inner dimension (the SwiGLU gate/up width).
int MaxPositionEmbeddings { get; set; } Maximum position (context length) the RoPE table was trained for.
int MoeIntermediateSize { get; set; } Routed-expert inner dimension (moe_intermediate_size); 0 when not an MoE decoder that distinguishes it from IntermediateSize.
int NumAttentionHeads { get; set; } Number of query attention heads.
int NumExpertsPerTok { get; set; } Experts activated per token (num_experts_per_tok); 0 for a dense decoder.
int NumHiddenLayers { get; set; } Number of stacked decoder blocks.
int NumKeyValueHeads { get; set; } Number of key/value heads.
int NumLocalExperts { get; set; } Number of MoE experts (num_local_experts or num_experts); 0 for a dense decoder.
int SharedExpertIntermediateSize { get; set; } Shared-expert inner dimension (Qwen2-MoE shared_expert_intermediate_size); 0 when absent.
int VocabSize { get; set; } Vocabulary size (embedding rows and LM-head columns).
int? BosTokenId { get; set; } Beginning-of-sequence token id, when declared.
int? EosTokenId { get; set; } End-of-sequence token id, when declared.
string HiddenActivation { get; set; } Feed-forward activation name, e.g.
string ModelType { get; set; } The short model type, e.g.
string TorchDtype { get; set; } On-disk weight precision, e.g.

Methods

Method Summary
HuggingFaceConfig FromFile(string path) Reads and parses a config.json file from disk.
HuggingFaceConfig Parse(string json) Parses a config.json from its JSON text.