micm_nlp.bootstrap¶
Process-level setup: .env loading, typed settings, and init().
Importing this module reads .env into os.environ, so libraries that consult
environment variables directly (huggingface_hub, transformers, wandb) see the same
values that Env exposes as typed settings.
init() is the one call an application makes at startup. It sets the workspace
root, strips the distributed-training variables that would otherwise push
accelerate into MULTI_GPU mode for a single-process run, and optionally installs
Rich pretty-printing and tracebacks.
Formerly split across env.py and setup.py; merged here in 0.2.0.
Attributes¶
Classes¶
Typed view of the environment, read from |
|
What |
|
Settings for Rich's pretty-printer and traceback handler. |
Functions¶
Module Contents¶
- class micm_nlp.bootstrap.Env¶
Bases:
pydantic_settings.BaseSettingsTyped view of the environment, read from
.envand the process env.extra='allow'andcase_sensitive=True: unknown variables are kept rather than rejected, so a project can put its own settings in the same.env. The module-levelenvinstance is built at import time; nothing re-reads the file afterwards.- APP_ENV: str = 'local'¶
- HF_TOKEN: str | None = None¶
- PROJECT_ROOT_PATH: pathlib.Path | None = None¶
- SHOW_LOCALS: int = 0¶
- WANDB_API_KEY: str | None = None¶
- model_config¶
- class micm_nlp.bootstrap.MicmNlpConfig¶
Bases:
pydantic.BaseModelWhat
init()accepts.root_pathdefaults toPROJECT_ROOT_PATHfrom the environment, soinit()with no arguments works when.envsets it.pretty_outputtakesTruefor Rich defaults, or aRichConfigto tune it.- pretty_output: RichConfig | bool = False¶
- root_path: str | None¶
- class micm_nlp.bootstrap.RichConfig¶
Bases:
pydantic.BaseModelSettings for Rich’s pretty-printer and traceback handler.
show_localsrenders local variables in tracebacks — useful when debugging, noisy in a training log.- extra_lines: int = 1¶
- show_locals: bool = False¶
- width: int = 120¶
- micm_nlp.bootstrap.init(config: MicmNlpConfig | dict) None¶
Set up the process: workspace root, distributed env, optional Rich output.
Call once before any pipeline call. Not triggered on import — until it runs, every accessor in
micm_nlp.pathraises, soartefacts/can never land in the wrong place by accident.Three things happen, in order: the workspace root is set from
root_path(falling back toPROJECT_ROOT_PATH); the distributed-training variables are stripped when this is a single-process run, see_disable_distributed_if_single_process; and Rich is installed ifpretty_outputasks for it.- Parameters:
config – a
MicmNlpConfigor a plain dict of its fields.
- micm_nlp.bootstrap.init_rich(rich_config: RichConfig | dict | bool) None¶
Install Rich’s pretty-printer and traceback handler.
Usually reached through
init()rather than called directly. Rich is imported inside the function, so a project that never asks for pretty output does not pay the import.- Parameters:
rich_config –
Truefor defaults, or aRichConfig/ dict.
- micm_nlp.bootstrap.env¶