micm_nlp.config

CONFIG — the YAML schema, validated.

CONFIG.from_yaml loads a run description into typed sections: task, peft, model, tokenizer, ds, eval, test, trainer, training_args, data_collator, custom_training_args, cuda and env. Loading also applies the env block to os.environ.

Two design points shape everything here.

Sections accept extra keys. Every section inherits from _Flex, which allows extras, implements the mapping protocol so dict(obj) and **obj expose both declared fields and extras, and recursively wraps nested dicts. YAML may therefore carry keys the schema does not declare, and runtime code may attach computed attributes (uuid4, param_size). Note vars(obj) does not see extras — pydantic keeps them in __pydantic_extra__; use dict(obj).

Class selection stays in YAML. trainer.cls, training_args.cls, data_collator.cls and model.pretrained.cls are thin shells: the real schema lives in HuggingFace, and the matching args block is splatted into the constructor at runtime.

Importing this module also widens PyYAML’s float resolver, so 5e-5 parses as a float rather than a string — YAML 1.1 otherwise requires a decimal point.

Classes

AdapterConfig

Locates a saved PEFT adapter to load: by name or uuid4, optionally

CONFIG

One run, fully described.

CudaConfig

The cuda block. empty_cache_steps frees the allocator cache every N

CustomTrainingArgsConfig

Settings this package adds beyond HuggingFace's TrainingArguments.

DataCollatorConfig

Thin shell. The actual schema lives in HF (DataCollatorForLanguageModeling,

DatasetConfig

The ds block: which dataset, where it lives, and how to read it.

EvalConfig

The eval block: when evaluation runs.

InitConfig

TRAIN-from-scratch spec: which model class to instantiate and which

InitModelConfigConfig

HF Config class + its constructor kwargs. Used in TRAIN mode to build

InputConfig

Which dataset column(s) hold the input.

LabelConfig

Which column holds the label, and what the label space is.

ModelConfig

The model block: architecture, and how the model is obtained.

PeftConfig

The peft block: which PEFT method, and how it is parameterized.

PostprocConfig

task.preproc_rules: what happens to predictions before metrics see them.

PretrainedConfig

Locates a pretrained model, and names the class to load it with.

SplitsConfig

Which splits a dataset already ships with.

TaskConfig

The task block: what is being learned and how it is scored.

TaskIdConfig

Which column identifies the task, for multi-task runs that score each

TestConfig

The test block: whether and how the held-out test split is scored.

TokenizerConfig

The tokenizer block: which tokenizer to load, or which to train.

TrainerConfig

Thin shell. cls selects which HF Trainer subclass to instantiate

TrainingArgsConfig

Thin shell. The actual schema lives in HF (TrainingArguments,

Module Contents

class micm_nlp.config.AdapterConfig

Bases: _Flex

Locates a saved PEFT adapter to load: by name or uuid4, optionally a specific checkpoint, from source.

checkpoint: str | None = None
name: str | None = None
source: str | None = None
uuid4: str | None = None
class micm_nlp.config.CONFIG

Bases: _Flex

One run, fully described.

Every section is optional except mode, because the same schema covers training, evaluation, preprocessing and tokenizer training – a preprocessing config has no training_args, and validation only demands what the mode needs. See from_yaml() for the entry point.

apply_env_vars() None

Copy the env block into os.environ, skipping null values.

Called by from_yaml(); exposed so a config built in code can do the same. Keys with a None value are left alone rather than cleared.

classmethod from_yaml(path: str | pathlib.Path) CONFIG

Load and validate a YAML file into a CONFIG.

Also records file_path and applies the env block to os.environ – so loading a config has a side effect on the process.

Parameters:

path – path to the YAML file.

Returns:

the validated config.

cuda: CudaConfig | None = None
custom_training_args: CustomTrainingArgsConfig | None = None
data_collator: DataCollatorConfig | None = None
ds: DatasetConfig | None = None
env: dict[str, str | None] | None = None
eval: EvalConfig | None = None
file_path: str | None = None
generation_config: _Flex | None = None
mode: micm_nlp.enums.ModeSE
model: ModelConfig | None = None
peft: PeftConfig | None = None
task: TaskConfig | None = None
test: TestConfig | None = None
tokenizer: TokenizerConfig | None = None
trainer: TrainerConfig | None = None
training_args: TrainingArgsConfig | None = None
class micm_nlp.config.CudaConfig

Bases: _Flex

The cuda block. empty_cache_steps frees the allocator cache every N steps, trading a little speed for headroom.

empty_cache_steps: int | None = None
class micm_nlp.config.CustomTrainingArgsConfig

Bases: _Flex

Settings this package adds beyond HuggingFace’s TrainingArguments.

Three groups. Batching: *_force_sequential and *_max_tokens_per_batch – mutually exclusive, since token-budget batching needs length-sorted order that a sequential sampler would override. Early stopping: patience, threshold, a floor before stopping is allowed, and a metric that is deliberately separable from the one used to pick the best checkpoint. Everything else: which columns to keep, per-parameter-group optimizer settings, a generation whitelist, and what to save at the end.

early_stopping_after: float | None = None
early_stopping_metric: str | None = None
early_stopping_patience: int | None = None
early_stopping_threshold: float | None = None
eval_force_sequential: bool = False
eval_max_tokens_per_batch: int | Literal['auto'] | None = None
generation_whitelist: list[str] | None = None
keep_only_final_model: bool = False
optimizer_grouped_parameters: list[_Flex] | None = None
random_task_exclusion: bool = False
save_final_model: bool = True
test_force_sequential: bool = False
test_max_tokens_per_batch: int | Literal['auto'] | None = None
train_force_sequential: bool = False
usable_columns: list[str] | None = None
class micm_nlp.config.DataCollatorConfig

Bases: _Flex

Thin shell. The actual schema lives in HF (DataCollatorForLanguageModeling, DataCollatorForSeq2Seq, etc.) or in our custom collators. cls selects which collator to instantiate; args is splatted into its constructor.

args: _Flex | None = None
cls: str | None = None
class micm_nlp.config.DatasetConfig

Bases: _Flex

The ds block: which dataset, where it lives, and how to read it.

dirs is a path template under artefacts/datasets/<category>; consumer repos substitute into it (a language segment, a fold) to assemble a run’s data.

Y: _Flex | None = None
category: str | None = None
comes_with_splits: SplitsConfig | None = None
descriptive_name: str | None = None
dirs: str | None = None
input: InputConfig | None = None
label: LabelConfig | None = None
name: str | None = None
preproc_rules: _Flex | None = None
task_id: TaskIdConfig | None = None
type: str | None = None
class micm_nlp.config.EvalConfig

Bases: _Flex

The eval block: when evaluation runs.

Before and after training, on the validation split or the test split, and during training. per_task groups metrics by task id.

after_training: bool = False
after_training_on_test: bool = False
before_training: bool = False
before_training_on_test: bool = False
downstream_tasks: bool | _Flex = False
during_training: bool | _Flex | None = None
per_task: _Flex | None = None
class micm_nlp.config.InitConfig

Bases: _Flex

TRAIN-from-scratch spec: which model class to instantiate and which HF config to pass it. Both cls fields fall back to arch-derived defaults when omitted.

cls: str | None = None
config: InitModelConfigConfig | None = None
class micm_nlp.config.InitModelConfigConfig

Bases: _Flex

HF Config class + its constructor kwargs. Used in TRAIN mode to build the model-config object (e.g. BertConfig) from scratch.

args: _Flex | None = None
cls: str | None = None
class micm_nlp.config.InputConfig

Bases: _Flex

Which dataset column(s) hold the input.

key_2 and key_3 cover pair and triple inputs (premise/hypothesis, context/question/answer). standardize_key renames the column to the canonical name instead of carrying the original through.

key: str
key_2: str | None = None
key_3: str | None = None
standardize_key: bool = False
class micm_nlp.config.LabelConfig

Bases: _Flex

Which column holds the label, and what the label space is.

names and number must agree when the config asks for id-to-name mapping; CONFIG validates that. padded is the id used to pad label sequences, which the loss ignores.

key: str
names: list[str] | None = None
number: int | None = None
padded: int | None = None
standardize_key: bool = False
class micm_nlp.config.ModelConfig

Bases: _Flex

The model block: architecture, and how the model is obtained.

Exactly one of init (build from scratch) or pretrained (load) is used, decided by mode. architecture is a free-form string used for run-directory naming – deliberately not validated against ModelArchSE. The param_size fields are filled in at runtime, not by YAML.

architecture: str
init: InitConfig | None = None
param_size: str | None = None
pretrained: PretrainedConfig | None = None
trainable_param_size: str | None = None
trainable_param_size_ratio: str | None = None
uuid4: str | None = None
class micm_nlp.config.PeftConfig

Bases: _Flex

The peft block: which PEFT method, and how it is parameterized.

A superset of the fields the supported methods need, so peft_type: LORA and peft_type: XPE share one schema; unused fields stay None. The encoder_* fields belong to the Cross-Prompt Encoder – notably encoder_ratio, which is what separates SPT (0), DUAL (between) and XPE (1).

encoder_dropout: float | None = None
encoder_embedding_freeze: bool = False
encoder_embedding_init_type: str = 'hf_default'
encoder_embedding_normalize: str | None = None
encoder_embedding_normalize_max_norm: float | None = None
encoder_freeze: bool = False
encoder_hidden_size: int | None = None
encoder_init_state_dict_path: str | None = None
encoder_input_size: int | None = None
encoder_num_layers: int | None = None
encoder_ratio: float | None = None
encoder_reparameterization_type: str | None = None
num_tasks: int | None = None
num_virtual_tokens: int | None = None
peft_type: str | None = None
task_type: str | None = None
class micm_nlp.config.PostprocConfig

Bases: _Flex

task.preproc_rules: what happens to predictions before metrics see them.

Each flag is a step – flatten, drop padded positions, decode ids to text, map label ids to names, strip and lowercase, coerce to float or back to ids – applied in the order evals.eval runs them. label_restricted_likelihood is the opt-in that scores only the candidate label tokens rather than the whole vocabulary.

calc_confusion_matrix: bool = False
decode: bool = False
filter_by_prefixes: bool | list[str] = False
filter_padded: bool = False
flatten: bool = False
label_id_to_name: bool = False
label_name_strip_lower: bool = False
label_name_to_float: bool = False
label_name_to_id: bool = False
label_restricted_likelihood: bool = False
prediction_axis: int = -1
verify_labels_match: bool = False
class micm_nlp.config.PretrainedConfig

Bases: _Flex

Locates a pretrained model, and names the class to load it with.

cls is resolved by name at runtime, so a new backbone usually needs no code change. An adapter here loads PEFT weights on top of the base model.

adapter: AdapterConfig | None = None
args: _Flex | None = None
checkpoint: str | None = None
cls: str | None = None
name: str | None = None
source: str | None = None
uuid4: str | None = None
class micm_nlp.config.SplitsConfig

Bases: _Flex

Which splits a dataset already ships with.

Each field is False when absent, or the split’s name when present – a string because the on-disk name is not always train/test/validation.

test: bool | str = False
train: bool | str = False
validation: bool | str = False
class micm_nlp.config.TaskConfig

Bases: _Flex

The task block: what is being learned and how it is scored.

metric_groups is a list because one run can score several tasks separately; preproc_rules is the post-processing chain applied before scoring.

category: str | None = None
id: str | None = None
metric_groups: list[_Flex] | None = None
name: str | None = None
preproc_rules: PostprocConfig | None = None
class micm_nlp.config.TaskIdConfig

Bases: _Flex

Which column identifies the task, for multi-task runs that score each task separately.

key: str
standardize_key: bool = False
class micm_nlp.config.TestConfig

Bases: _Flex

The test block: whether and how the held-out test split is scored.

zero_shot adds an untrained baseline pass; zero_shot_only skips training altogether, which is how a zero-shot row is produced.

report_to_wandb: bool = False
run: bool = False
save_predictions: bool = False
zero_shot: bool = False
zero_shot_only: bool = False
class micm_nlp.config.TokenizerConfig

Bases: _Flex

The tokenizer block: which tokenizer to load, or which to train.

adapt_to_lm applies the target architecture’s special tokens and post-processor to a tokenizer borrowed from elsewhere.

adapt_to_lm: bool = False
algorithm: str | None = None
name: str | None = None
source: str | None = None
type: str | None = None
vocab_size: int | None = None
class micm_nlp.config.TrainerConfig

Bases: _Flex

Thin shell. cls selects which HF Trainer subclass to instantiate (Trainer, Seq2SeqTrainer, …). args is reserved for future extra kwargs splatted into the trainer ctor (runtime wiring currently fills the rest).

args: _Flex | None = None
cls: str | None = None
class micm_nlp.config.TrainingArgsConfig

Bases: _Flex

Thin shell. The actual schema lives in HF (TrainingArguments, Seq2SeqTrainingArguments, etc.). cls selects which HF dataclass to instantiate; args is splatted into its constructor at runtime.

For tokenizer-training configs, cls may name a non-HF trainer (e.g. SentencePieceTrainer) and args carries that trainer’s kwargs.

args: _Flex | None = None
cls: str | None = None