metadata
metadata
¶
Model-family metadata for prompt formatting, RoPE scaling, and runtime bookkeeping.
Provides ModelMetadata and its per-family subclasses (Llama32,
Mistral, Qwen, etc.) that capture prompt templates, special-token
settings, and context-window configuration. The RopeScaling model
handles context-window extension via Rotary Position Embeddings.
A global maximum sequence length (GLOBAL_MAX_SEQ_LENGTH = 2048 * 6)
is applied as a safety cap to prevent OOM and underfitting errors.
Classes:
| Name | Description |
|---|---|
LLMPromptConfig |
Prompt template and special-token settings. |
RopeScaling |
RoPE scaling parameters for context-window extension. |
ModelMetadata |
Base container for model-family-specific metadata. |
Granite |
IBM Granite family metadata. |
Llama32 |
Meta Llama 3.2 family metadata. |
Mistral |
Mistral AI family metadata. |
Nemotron |
NVIDIA Nemotron family metadata. |
Qwen |
Alibaba Qwen family metadata. |
SmolLM2 |
HuggingFace SmolLM2 family metadata. |
SmolLM3 |
HuggingFace SmolLM3 family metadata. |
TinyLlama |
TinyLlama family metadata. |
Functions:
| Name | Description |
|---|---|
resolve_rope_scaling_factor |
Normalize a rope-scaling specification into a |
get_base_max_seq_length |
Derive the base max sequence length from a model config. |
LLMPromptConfig
pydantic-model
¶
Bases: BaseModel
Prompt template and special-token settings for an LLM.
Holds the Jinja-style prompt template together with flags and
token values that control how BOS/EOS markers are injected during
training and inference.
Fields:
-
template(str) -
add_bos_token_to_prompt(bool) -
add_eos_token_to_prompt(bool) -
bos_token(str) -
bos_token_id(int) -
eos_token(str) -
eos_token_id(int)
template
pydantic-field
¶
Prompt template with {instruction}, {schema}, and {prefill} placeholders.
{instruction}-- task directive telling the model what to generate (e.g. "Generate a JSONL dataset with the following columns: ").{schema}-- column schema fragment listing expected output fields, typically formatted as"col":<unk>,"col2":<unk>.{prefill}-- optional text injected at the start of the model's response to steer generation, currently used for time series data.
add_bos_token_to_prompt
pydantic-field
¶
Whether to prepend the BOS token to the prompt.
add_eos_token_to_prompt
pydantic-field
¶
Whether to append the EOS token to the prompt.
bos_token
pydantic-field
¶
Beginning-of-sequence token string.
bos_token_id
pydantic-field
¶
Integer id for the BOS token.
eos_token
pydantic-field
¶
End-of-sequence token string.
eos_token_id
pydantic-field
¶
Integer id for the EOS token.
from_tokenizer(name, tokenizer=None, **kwargs)
classmethod
¶
Create a prompt config by reading from settings of a tokenizer.
If no tokenizer is supplied one is loaded from name
via AutoTokenizer.from_pretrained. Individual fields can
be overridden through **kwargs (e.g. bos_token,
template).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
HuggingFace model identifier used to load the
tokenizer when |
required |
tokenizer
|
AutoTokenizer | None
|
Optional pre-loaded tokenizer instance. |
None
|
**kwargs
|
Overrides for any |
{}
|
Returns:
| Type | Description |
|---|---|
LLMPromptConfig
|
A new |
Source code in src/nemo_safe_synthesizer/llm/metadata.py
RopeScaling
pydantic-model
¶
Bases: BaseModel
Rotary Position Embedding (RoPE) scaling configuration.
Encapsulates the parameters needed to extend a model's context
window via RoPE scaling. Will be superseded by
RotaryEmbeddingConfigMixin when available in transformers v5.
Fields:
Validators:
rope_type = 'default'
pydantic-field
¶
Scaling algorithm: linear, dynamic, default, yarn, or llama3.
factor = 1.0
pydantic-field
¶
Multiplier for RoPE scaling to extend the context window; values above MAX_ROPE_SCALING_FACTOR are clamped.
theta = 10000.0
pydantic-field
¶
Theta for rope scaling.
validate_factor(v)
pydantic-validator
¶
Clamp factor to MAX_ROPE_SCALING_FACTOR and warn if exceeded.
Source code in src/nemo_safe_synthesizer/llm/metadata.py
from_autoconfig(config, factor=None)
classmethod
¶
Create a RopeScaling from a HuggingFace PretrainedConfig.
Reads the model's native rope_theta and rope_type and
optionally overrides the scaling factor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
PretrainedConfig
|
A loaded HuggingFace model config. |
required |
factor
|
float | int | None
|
Scaling factor override. Defaults to |
None
|
Returns:
| Type | Description |
|---|---|
'RopeScaling'
|
A |
Source code in src/nemo_safe_synthesizer/llm/metadata.py
to_hf_dict()
¶
Convert to the HuggingFace rope_scaling dict format.
Returns None when factor is 1.0 (no scaling).
Returns:
| Type | Description |
|---|---|
dict | None
|
A dict with keys |
dict | None
|
or |
Source code in src/nemo_safe_synthesizer/llm/metadata.py
ModelMetadata
pydantic-model
¶
Bases: BaseModel
Base container for model-family-specific metadata.
Stores prompt formats, special tokens, RoPE scaling parameters, and
runtime bookkeeping needed to load, fine-tune, and generate with a
given LLM family. Each supported model family has a concrete
subclass (e.g. Llama32, Mistral) that sets the correct
defaults.
Use the factory methods from_str_or_path,
from_config,
or from_metadata_json
to construct instances rather than calling the constructor directly.
Config:
arbitrary_types_allowed:True
Fields:
-
model_name_or_path(str) -
prompt_config(LLMPromptConfig) -
autoconfig(PretrainedConfig) -
base_max_seq_length(int | None) -
rope_scaling(RopeScaling | None) -
max_sequences_per_example(int | None) -
workdir(Workdir | None) -
is_adapter(bool) -
instruction(str) -
rope_parameters_location(Literal['autoconfig', 'automodel']) -
initial_prefill(dict[str, str] | str | None)
Validators:
model_name_or_path
pydantic-field
¶
HuggingFace model identifier or local path.
prompt_config
pydantic-field
¶
Prompt template and token settings.
autoconfig
pydantic-field
¶
HuggingFace PretrainedConfig (excluded from serialization).
base_max_seq_length = None
pydantic-field
¶
Supported context window for base model, before rope scaling factor adjustment.
rope_scaling = None
pydantic-field
¶
RoPE scaling configuration for context window extension. Accepts a RopeScaling instance, a dict of RopeScaling fields, a numeric scale factor (requires autoconfig), or None.
max_sequences_per_example = None
pydantic-field
¶
Cap on sequences packed into one training example.
Resolved by AutoConfigResolver to 1 when DP is enabled,
10 when DP is disabled and set to "auto", or a
user-supplied integer.
workdir = None
pydantic-field
¶
Artifact directory layout.
is_adapter = False
pydantic-field
¶
Whether an adapter checkpoint is loaded.
instruction = DEFAULT_INSTRUCTION
pydantic-field
¶
Default system instruction text.
rope_parameters_location = 'automodel'
pydantic-field
¶
Where to read RoPE parameters from: autoconfig or automodel.
initial_prefill = None
pydantic-field
¶
Currently used for time series data. May be a single string or a per-column dict.
adapter_path
property
¶
The path where adapter model files are stored.
Raises:
| Type | Description |
|---|---|
ValueError
|
If workdir is not set. |
metadata_path
property
¶
The path to the metadata JSON file.
Uses workdir.metadata_file which automatically resolves to the
parent workdir's path when resuming for generation.
Raises:
| Type | Description |
|---|---|
ValueError
|
If workdir is not set. |
rope_scaling_factor
property
¶
The rope scaling factor for backwards compatibility.
max_seq_length
property
¶
Actual context window for training.
Includes any adjustment for rope_scaling.factor.
populate_derived_fields(data)
pydantic-validator
¶
Auto-populate autoconfig, rope_scaling, and base_max_seq_length.
Called by Pydantic before field validation. Loads an
AutoConfig from model_name_or_path when one is not
already present, derives base_max_seq_length from that
config, and resolves the rope_scaling specification into a
RopeScaling instance (or None).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
dict
|
Raw field values dict supplied to the constructor. |
required |
Returns:
| Type | Description |
|---|---|
dict
|
The mutated |
Source code in src/nemo_safe_synthesizer/llm/metadata.py
serialize_autoconfig(config)
¶
Serialize PretrainedConfig to a plain dict for JSON export.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
PretrainedConfig
|
The HuggingFace config to serialize. |
required |
Returns:
| Type | Description |
|---|---|
dict
|
Dict representation of the config. |
Source code in src/nemo_safe_synthesizer/llm/metadata.py
save_metadata()
¶
Save model metadata to JSON file.
Raises:
| Type | Description |
|---|---|
ValueError
|
If workdir is not set. |
Source code in src/nemo_safe_synthesizer/llm/metadata.py
from_str_or_path(model_name_or_path, **kwargs)
classmethod
¶
Instantiate the correct ModelMetadata subclass from a model name or path.
Performs case-insensitive substring matching of each registered
subclass name against model_name_or_path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_name_or_path
|
Path | str
|
HuggingFace model identifier or local filesystem path. |
required |
**kwargs
|
Forwarded to the matched subclass constructor. |
{}
|
Returns:
| Type | Description |
|---|---|
ModelMetadata
|
An instance of the matched |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no registered subclass matches. |
Source code in src/nemo_safe_synthesizer/llm/metadata.py
from_config(config, workdir=None)
classmethod
¶
Create ModelMetadata from SafeSynthesizerParameters.
The config should have been resolved with
AutoConfigResolver before calling this method.
If rope_scaling_factor is set, a RopeScaling object is
created with the model's native theta.
max_sequences_per_example is always forwarded from
config.data -- AutoConfigResolver resolves it to 1
when DP is enabled, 10 when set to "auto" with DP
disabled, or the user-supplied integer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
SafeSynthesizerParameters
|
Resolved parameters with model and training configuration. |
required |
workdir
|
Workdir | None
|
Artifact directory layout. Required for saving model artifacts. |
None
|
Returns:
| Type | Description |
|---|---|
ModelMetadata
|
A |
ModelMetadata
|
configured pretrained model. |
Source code in src/nemo_safe_synthesizer/llm/metadata.py
from_metadata_json(path, workdir=None)
classmethod
¶
Load ModelMetadata from a saved JSON file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path | str
|
Path to the metadata JSON file. |
required |
workdir
|
Workdir | None
|
Workdir instance for artifact paths. If not provided, will be None. |
None
|
Returns:
| Type | Description |
|---|---|
ModelMetadata
|
ModelMetadata instance with the loaded configuration. |
Source code in src/nemo_safe_synthesizer/llm/metadata.py
Granite(model_name_or_path, tokenizer=None, rope_scaling_factor=None, **kwargs)
pydantic-model
¶
Bases: ModelMetadata
Metadata for IBM Granite model family.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_name_or_path
|
str
|
HuggingFace model identifier or local path. |
required |
tokenizer
|
Optional pre-loaded tokenizer. |
None
|
|
rope_scaling_factor
|
float | None
|
Optional RoPE scaling factor. |
None
|
**kwargs
|
Forwarded to |
{}
|
Fields:
-
model_name_or_path(str) -
prompt_config(LLMPromptConfig) -
autoconfig(PretrainedConfig) -
base_max_seq_length(int | None) -
rope_scaling(RopeScaling | None) -
max_sequences_per_example(int | None) -
workdir(Workdir | None) -
is_adapter(bool) -
instruction(str) -
rope_parameters_location(Literal['autoconfig', 'automodel']) -
initial_prefill(dict[str, str] | str | None)
Validators:
Source code in src/nemo_safe_synthesizer/llm/metadata.py
Llama32(model_name_or_path, tokenizer=None, rope_scaling_factor=None, **kwargs)
pydantic-model
¶
Bases: ModelMetadata
Metadata for Meta Llama 3.2 model family.
Uses <|im_start|> (id 151644) as the BOS token and disables
automatic BOS/EOS injection in prompts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_name_or_path
|
str
|
HuggingFace model identifier or local path. |
required |
tokenizer
|
Optional pre-loaded tokenizer. |
None
|
|
rope_scaling_factor
|
float | None
|
Optional RoPE scaling factor. |
None
|
**kwargs
|
Forwarded to |
{}
|
Fields:
-
model_name_or_path(str) -
prompt_config(LLMPromptConfig) -
autoconfig(PretrainedConfig) -
base_max_seq_length(int | None) -
rope_scaling(RopeScaling | None) -
max_sequences_per_example(int | None) -
workdir(Workdir | None) -
is_adapter(bool) -
instruction(str) -
rope_parameters_location(Literal['autoconfig', 'automodel']) -
initial_prefill(dict[str, str] | str | None)
Validators:
Source code in src/nemo_safe_synthesizer/llm/metadata.py
Mistral(model_name_or_path, tokenizer=None, rope_scaling_factor=None, **kwargs)
pydantic-model
¶
Bases: ModelMetadata
Metadata for Mistral AI model family.
RoPE scaling is not supported for Mistral models. Any supplied
rope_scaling_factor will be ignored with a warning.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_name_or_path
|
str
|
HuggingFace model identifier or local path. |
required |
tokenizer
|
AutoTokenizer | None
|
Optional pre-loaded tokenizer. |
None
|
rope_scaling_factor
|
float | None
|
Ignored with a warning if provided. |
None
|
**kwargs
|
Forwarded to |
{}
|
Fields:
-
model_name_or_path(str) -
prompt_config(LLMPromptConfig) -
autoconfig(PretrainedConfig) -
base_max_seq_length(int | None) -
rope_scaling(RopeScaling | None) -
max_sequences_per_example(int | None) -
workdir(Workdir | None) -
is_adapter(bool) -
instruction(str) -
rope_parameters_location(Literal['autoconfig', 'automodel']) -
initial_prefill(dict[str, str] | str | None)
Validators:
Source code in src/nemo_safe_synthesizer/llm/metadata.py
Nemotron(model_name_or_path, tokenizer=None, rope_scaling_factor=None, **kwargs)
pydantic-model
¶
Bases: ModelMetadata
Metadata for NVIDIA Nemotron model family.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_name_or_path
|
str
|
HuggingFace model identifier or local path. |
required |
tokenizer
|
Optional pre-loaded tokenizer. |
None
|
|
rope_scaling_factor
|
float | None
|
Optional RoPE scaling factor. |
None
|
**kwargs
|
Forwarded to |
{}
|
Fields:
-
model_name_or_path(str) -
prompt_config(LLMPromptConfig) -
autoconfig(PretrainedConfig) -
base_max_seq_length(int | None) -
rope_scaling(RopeScaling | None) -
max_sequences_per_example(int | None) -
workdir(Workdir | None) -
is_adapter(bool) -
instruction(str) -
rope_parameters_location(Literal['autoconfig', 'automodel']) -
initial_prefill(dict[str, str] | str | None)
Validators:
Source code in src/nemo_safe_synthesizer/llm/metadata.py
Qwen(model_name_or_path, tokenizer=None, rope_scaling_factor=None, **kwargs)
pydantic-model
¶
Bases: ModelMetadata
Metadata for Alibaba Qwen model family.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_name_or_path
|
str
|
HuggingFace model identifier or local path. |
required |
tokenizer
|
Optional pre-loaded tokenizer. |
None
|
|
rope_scaling_factor
|
float | None
|
Optional RoPE scaling factor. |
None
|
**kwargs
|
Forwarded to |
{}
|
Fields:
-
model_name_or_path(str) -
prompt_config(LLMPromptConfig) -
autoconfig(PretrainedConfig) -
base_max_seq_length(int | None) -
rope_scaling(RopeScaling | None) -
max_sequences_per_example(int | None) -
workdir(Workdir | None) -
is_adapter(bool) -
instruction(str) -
rope_parameters_location(Literal['autoconfig', 'automodel']) -
initial_prefill(dict[str, str] | str | None)
Validators:
Source code in src/nemo_safe_synthesizer/llm/metadata.py
SmolLM2(model_name_or_path, tokenizer=None, rope_scaling_factor=None, **kwargs)
pydantic-model
¶
Bases: ModelMetadata
Metadata for HuggingFace SmolLM2 model family (e.g. SmolLM2-135M).
RoPE scaling is not supported and any supplied rope_scaling_factor
will be ignored with a warning.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_name_or_path
|
str
|
HuggingFace model identifier or local path. |
required |
tokenizer
|
Optional pre-loaded tokenizer. |
None
|
|
rope_scaling_factor
|
float | None
|
Ignored with a warning if provided. |
None
|
**kwargs
|
Forwarded to |
{}
|
Fields:
-
model_name_or_path(str) -
prompt_config(LLMPromptConfig) -
autoconfig(PretrainedConfig) -
base_max_seq_length(int | None) -
rope_scaling(RopeScaling | None) -
max_sequences_per_example(int | None) -
workdir(Workdir | None) -
is_adapter(bool) -
instruction(str) -
rope_parameters_location(Literal['autoconfig', 'automodel']) -
initial_prefill(dict[str, str] | str | None)
Validators:
Source code in src/nemo_safe_synthesizer/llm/metadata.py
SmolLM3(model_name_or_path, tokenizer=None, rope_scaling_factor=None, **kwargs)
pydantic-model
¶
Bases: ModelMetadata
Metadata for HuggingFace SmolLM3 model family.
Uses <|im_start|> (id 128011) as the BOS token. RoPE scaling
is not supported. Any supplied rope_scaling_factor will be
ignored with a warning.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_name_or_path
|
str
|
HuggingFace model identifier or local path. |
required |
tokenizer
|
Optional pre-loaded tokenizer. |
None
|
|
rope_scaling_factor
|
float | None
|
Ignored with a warning if provided. |
None
|
**kwargs
|
Forwarded to |
{}
|
Fields:
-
model_name_or_path(str) -
prompt_config(LLMPromptConfig) -
autoconfig(PretrainedConfig) -
base_max_seq_length(int | None) -
rope_scaling(RopeScaling | None) -
max_sequences_per_example(int | None) -
workdir(Workdir | None) -
is_adapter(bool) -
instruction(str) -
rope_parameters_location(Literal['autoconfig', 'automodel']) -
initial_prefill(dict[str, str] | str | None)
Validators:
Source code in src/nemo_safe_synthesizer/llm/metadata.py
TinyLlama(model_name_or_path, tokenizer=None, rope_scaling_factor=None, **kwargs)
pydantic-model
¶
Bases: ModelMetadata
Metadata for the TinyLlama model family.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_name_or_path
|
str
|
HuggingFace model identifier or local path. |
required |
tokenizer
|
Optional pre-loaded tokenizer. |
None
|
|
rope_scaling_factor
|
float | None
|
Optional RoPE scaling factor. |
None
|
**kwargs
|
Forwarded to |
{}
|
Fields:
-
model_name_or_path(str) -
prompt_config(LLMPromptConfig) -
autoconfig(PretrainedConfig) -
base_max_seq_length(int | None) -
rope_scaling(RopeScaling | None) -
max_sequences_per_example(int | None) -
workdir(Workdir | None) -
is_adapter(bool) -
instruction(str) -
rope_parameters_location(Literal['autoconfig', 'automodel']) -
initial_prefill(dict[str, str] | str | None)
Validators:
Source code in src/nemo_safe_synthesizer/llm/metadata.py
resolve_rope_scaling_factor(factor=None, autoconfig=None)
¶
Normalize a rope-scaling specification into a RopeScaling or None.
Accepts several convenience representations and converts them into a
canonical RopeScaling instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
factor
|
float | int | RopeScaling | dict | None
|
The scaling specification. Accepted forms:
|
None
|
autoconfig
|
PretrainedConfig | None
|
A HuggingFace |
None
|
Returns:
| Type | Description |
|---|---|
RopeScaling | None
|
A |
Raises:
| Type | Description |
|---|---|
ValueError
|
If a numeric |
Source code in src/nemo_safe_synthesizer/llm/metadata.py
get_base_max_seq_length(config)
¶
Derive the base max sequence length from a model config.
Reads max_position_embeddings from the config and clamps it to
GLOBAL_MAX_SEQ_LENGTH to prevent OOM and underfitting errors.
Falls back to DEFAULT_MAX_SEQ_LENGTH when the attribute is
absent.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
AutoConfig
|
A HuggingFace |
required |
Returns:
| Type | Description |
|---|---|
int
|
The effective base sequence length (before RoPE scaling). |