micm_nlp.training.run_output

A run’s output directory, and everything the trainer writes into it that is not a metric or a prediction.

RunOutput is constructed by the trainer before the HuggingFace arguments exist (they need the directory) and holds: the directory, the static columns stamped onto every metrics row, the config snapshot (config.yml – the config as the framework resolved it, written before anything non-serialisable can reach it), info.json (environment, paths, the values the trainer resolved, the wandb identity, start/finish) and the model / wandb symlinks. Metrics and predictions files are written by micm_nlp.evals.results, into RunOutput.file().

The config is read-only for the trainer: what the run did is recorded here, never written back into the config.

Attributes

Classes

RunOutput

One run's output directory.

Functions

environment_info(→ dict[str, Any])

What the run ran on: every SLURM* variable, host, interpreter, visible

output_dir_for(→ str)

The directory a run writes into.

package_commit(→ str | None)

This package's own commit, -dirty when its tree has uncommitted changes;

wandb_info(→ dict[str, Any] | None)

Identity and location of a wandb run, or None without one.

write_config(→ pathlib.Path)

Save a config as plain YAML (enums as strings) into dir_, creating it.

write_run_info(→ pathlib.Path)

Merge sections into <dir_>/info.json (read-modify-write).

Module Contents

class micm_nlp.training.run_output.RunOutput(config, model)

One run’s output directory.

Parameters:
  • config – the run’s config; its output block (if any) supplies the directory, the file prefix, the config file name and static columns.

  • model – the MODEL – its name names a solo run’s directory, its uuid4 is stamped on every row, its path (when the mode has a checkpoint dir) is linked as model.

file(name: str) → pathlib.Path

The path of one of this run’s files, with the output prefix applied.

A symlink dir/name -> target (absolute), so every artefact of the run is reachable from its directory.

A target that does not exist yet still gets a link – the checkpoint directory appears only when the trainer saves. A link that already points at target is left alone; one that points elsewhere is replaced. None is a no-op.

note_wandb(run) → None

Record the wandb run’s id, url and local dir, and link the dir.

record(kind: str, event: str, rows: list[dict[str, Any]]) → None

Keep the rows of one written file, so the run is readable in memory.

Called by save_metrics() and save_predictions() as they write, which is why nothing in TRAINER has to collect results: whatever reaches disk is here, under the same event name, in the same row shape the CSV holds. That equality is the point – it is what lets a future RunOutput.load(dir) read a finished run back into the same attributes rather than a second, parallel shape.

Parameters:
  • kind – 'results' for a metrics file, 'predictions' for a predictions file – the two kinds a run writes.

  • event – the event name the file is named for (test_after_train).

resolved(**values) → None

Record the values the trainer derived from the config (the seed it drew, the prefixed metric_for_best_model, fp16 by device) in info.json – under resolved, or <prefix>resolved for a prefixed trainer (a separate_test config, or a runner-set prefix), so two never overwrite each other – and stamp seed as a column unless the config pinned one (a separate_test trainer stamps the seed its own process used; it inherits a pinned one through output.columns).

write_run_info(**sections) → pathlib.Path

Merge sections into this run’s info.json; see the module function.

The merged result is read back into info, so the attribute always equals the file rather than a parallel accumulation of the same sections.

columns: dict[str, Any]
dir
info: dict[str, Any]
predictions: dict[str, list[dict[str, Any]]]
prefix
results: dict[str, list[dict[str, Any]]]
micm_nlp.training.run_output.environment_info() → dict[str, Any]

What the run ran on: every SLURM* variable, host, interpreter, visible GPUs, and the versions of the packages that decide numerics.

The scheduler block is one glob rather than a hand-kept list, so a variable the scheduler adds tomorrow is recorded without a code change.

micm_nlp.training.run_output.output_dir_for(config, model_name: str) → str

The directory a run writes into.

output.dir wins when set – the group runner puts the run there. Otherwise the run belongs to no group and lands under runs/units/{model_name}, where model_name is the generated name (uuid first), unique and equal to the wandb run name.

micm_nlp.training.run_output.package_commit() → str | None

This package’s own commit, -dirty when its tree has uncommitted changes; None when it is an installed copy rather than a checkout.

The version alone does not identify the code: an editable install follows a working tree that moves between releases, which is how a result stops being reproducible.

micm_nlp.training.run_output.wandb_info(run) → dict[str, Any] | None

Identity and location of a wandb run, or None without one.

dir is the run directory (the parent of run.dir, which is its files/); url is None offline, where some wandb versions raise on the property.

micm_nlp.training.run_output.write_config(dir_: str | pathlib.Path, config, filename: str = CONFIG_FILE) → pathlib.Path

Save a config as plain YAML (enums as strings) into dir_, creating it.

micm_nlp.training.run_output.write_run_info(dir_: str | pathlib.Path, **sections) → pathlib.Path

Merge sections into <dir_>/info.json (read-modify-write).

Dict-valued sections merge one level deep; started is kept from the first write; everything else is latest-wins. Values must be JSON-serialisable.

micm_nlp.training.run_output.CONFIG_FILE = 'config.yml'
micm_nlp.training.run_output.RUN_INFO_FILE = 'info.json'
micm_nlp.training.run_output.TEST_CONFIG_FILE = 'test_config.yml'