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¶
Locates a saved PEFT adapter to load: by |
|
One run, fully described. |
|
The |
|
Settings this package adds beyond HuggingFace's |
|
Thin shell. The actual schema lives in HF (DataCollatorForLanguageModeling, |
|
The |
|
The |
|
TRAIN-from-scratch spec: which model class to instantiate and which |
|
HF Config class + its constructor kwargs. Used in TRAIN mode to build |
|
Which dataset column(s) hold the input. |
|
Which column holds the label, and what the label space is. |
|
The |
|
The |
|
|
|
Locates a pretrained model, and names the class to load it with. |
|
Which splits a dataset already ships with. |
|
The |
|
Which column identifies the task, for multi-task runs that score each |
|
The |
|
The |
|
Thin shell. cls selects which HF Trainer subclass to instantiate |
|
Thin shell. The actual schema lives in HF (TrainingArguments, |
Module Contents¶
- class micm_nlp.config.AdapterConfig¶
Bases:
_FlexLocates a saved PEFT adapter to load: by
nameoruuid4, optionally a specificcheckpoint, fromsource.- checkpoint: str | None = None¶
- name: str | None = None¶
- source: str | None = None¶
- uuid4: str | None = None¶
- class micm_nlp.config.CONFIG¶
Bases:
_FlexOne run, fully described.
Every section is optional except
mode, because the same schema covers training, evaluation, preprocessing and tokenizer training – a preprocessing config has notraining_args, and validation only demands what the mode needs. Seefrom_yaml()for the entry point.- apply_env_vars() None¶
Copy the
envblock intoos.environ, skipping null values.Called by
from_yaml(); exposed so a config built in code can do the same. Keys with aNonevalue 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_pathand applies theenvblock toos.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:
_FlexThe
cudablock.empty_cache_stepsfrees the allocator cache every N steps, trading a little speed for headroom.- empty_cache_steps: int | None = None¶
- class micm_nlp.config.CustomTrainingArgsConfig¶
Bases:
_FlexSettings this package adds beyond HuggingFace’s
TrainingArguments.Three groups. Batching:
*_force_sequentialand*_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:
_FlexThin 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:
_FlexThe
dsblock: which dataset, where it lives, and how to read it.dirsis a path template underartefacts/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:
_FlexThe
evalblock: when evaluation runs.Before and after training, on the validation split or the test split, and during training.
per_taskgroups 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:
_FlexTRAIN-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:
_FlexHF 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:
_FlexWhich dataset column(s) hold the input.
key_2andkey_3cover pair and triple inputs (premise/hypothesis, context/question/answer).standardize_keyrenames 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:
_FlexWhich column holds the label, and what the label space is.
namesandnumbermust agree when the config asks for id-to-name mapping;CONFIGvalidates that.paddedis 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:
_FlexThe
modelblock: architecture, and how the model is obtained.Exactly one of
init(build from scratch) orpretrained(load) is used, decided bymode.architectureis a free-form string used for run-directory naming – deliberately not validated againstModelArchSE. Theparam_sizefields 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:
_FlexThe
peftblock: which PEFT method, and how it is parameterized.A superset of the fields the supported methods need, so
peft_type: LORAandpeft_type: XPEshare one schema; unused fields stayNone. Theencoder_*fields belong to the Cross-Prompt Encoder – notablyencoder_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_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:
_Flextask.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.evalruns them.label_restricted_likelihoodis 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:
_FlexLocates a pretrained model, and names the class to load it with.
clsis resolved by name at runtime, so a new backbone usually needs no code change. Anadapterhere 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:
_FlexWhich splits a dataset already ships with.
Each field is
Falsewhen absent, or the split’s name when present – a string because the on-disk name is not alwaystrain/test/validation.- test: bool | str = False¶
- train: bool | str = False¶
- validation: bool | str = False¶
- class micm_nlp.config.TaskConfig¶
Bases:
_FlexThe
taskblock: what is being learned and how it is scored.metric_groupsis a list because one run can score several tasks separately;preproc_rulesis 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:
_FlexWhich 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:
_FlexThe
testblock: whether and how the held-out test split is scored.zero_shotadds an untrained baseline pass;zero_shot_onlyskips 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:
_FlexThe
tokenizerblock: which tokenizer to load, or which to train.adapt_to_lmapplies 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:
_FlexThin 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:
_FlexThin 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¶