wandb_setup
wandb_setup
¶
WandB integration for Safe Synthesizer.
This module provides WandB (Weights & Biases) integration for experiment tracking, including run initialization, configuration logging, and failure reporting.
Classes:
| Name | Description |
|---|---|
WandbMode |
WandB run mode. |
WandbPhase |
Phase of the Safe Synthesizer pipeline. |
WandbSettings |
WandB configuration for Safe Synthesizer. |
WandbLoggable |
Structural type for observability events that can be logged to wandb. |
Functions:
| Name | Description |
|---|---|
resolve_wandb_run_id |
Resolve a wandb run ID from a string or file path. |
log_failure_to_wandb |
Log failure to wandb before exiting. |
publish_evaluation_report |
Best-effort publish final evaluation media for a CLI-managed run. |
update_wandb_config |
Update the wandb config with the given configuration. |
initialize_wandb_run |
Initialize or resume a wandb run with consistent configuration. |
log_observability_event |
Log an observability event to the currently active wandb run. |
WandbMode
¶
Bases: str, Enum
WandB run mode.
WandbPhase
¶
Bases: str, Enum
Phase of the Safe Synthesizer pipeline.
WandbSettings
¶
Bases: BaseSettings
WandB configuration for Safe Synthesizer.
All settings can be configured via environment variables.
Methods:
| Name | Description |
|---|---|
validate_wandb_mode |
Coerce string or None to |
validate_phase |
Coerce string or None to |
Attributes:
| Name | Type | Description |
|---|---|---|
wandb_mode |
WandbMode
|
Run mode, one of online, offline, or disabled (env variable: |
wandb_project |
str | None
|
WandB project name override (env variable: |
exp_name |
str
|
Fallback project name when |
phase |
WandbPhase
|
Current pipeline phase for WandB grouping. |
effective_wandb_project |
str
|
Effective wandb project name, falling back to |
wandb_mode = Field(default=(WandbMode.DISABLED), description='Run mode, one of online, offline, or disabled.', validation_alias=(AliasChoices('WANDB_MODE', 'NSS_WANDB_MODE')))
class-attribute
instance-attribute
¶
Run mode, one of online, offline, or disabled (env variable: WANDB_MODE or NSS_WANDB_MODE).
wandb_project = Field(default=None, description='WandB project name override.', validation_alias=(AliasChoices('WANDB_PROJECT', 'NSS_WANDB_PROJECT')))
class-attribute
instance-attribute
¶
WandB project name override (env variable: WANDB_PROJECT or NSS_WANDB_PROJECT).
exp_name = Field(default='nss_experiments', description='Fallback project name when ``wandb_project`` is not set.')
class-attribute
instance-attribute
¶
Fallback project name when wandb_project is not set.
phase = Field(default=(WandbPhase.UNKNOWN), description='Current pipeline phase for WandB grouping.')
class-attribute
instance-attribute
¶
Current pipeline phase for WandB grouping.
effective_wandb_project
property
¶
Effective wandb project name, falling back to exp_name.
validate_wandb_mode(v)
classmethod
¶
Coerce string or None to WandbMode enum, defaulting to DISABLED.
Source code in src/nemo_safe_synthesizer/cli/wandb_setup.py
validate_phase(v)
classmethod
¶
Coerce string or None to WandbPhase, defaulting to UNKNOWN.
Source code in src/nemo_safe_synthesizer/cli/wandb_setup.py
WandbLoggable
¶
Bases: Protocol
Structural type for observability events that can be logged to wandb.
Any event exposing to_wandb_payload(prefix) -> dict satisfies this --
e.g. TrainingObservability and the generation-side
GenerationObservability. Using a Protocol keeps :func:log_observability_event
decoupled from the concrete event types (no import of the training/generation
subpackages from this CLI module).
Methods:
| Name | Description |
|---|---|
to_wandb_payload |
Return wandb metrics for this event, namespaced under |
resolve_wandb_run_id(id_or_path)
¶
Resolve a wandb run ID from a string or file path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id_or_path
|
str
|
Either a wandb run ID string, or a path to a file containing the ID. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The resolved wandb run ID. |
Source code in src/nemo_safe_synthesizer/cli/wandb_setup.py
log_failure_to_wandb(error, phase)
¶
Log failure to wandb before exiting.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
error
|
Exception
|
The exception that caused the failure |
required |
phase
|
str
|
The phase where failure occurred (e.g., "train", "generation", "end_to_end") |
required |
Source code in src/nemo_safe_synthesizer/cli/wandb_setup.py
publish_evaluation_report(workdir, summary, upload_report)
¶
Best-effort publish final evaluation media for a CLI-managed run.
The scorecard is always sent when W&B is active. HTML and files leave the
local machine only when upload_report is explicitly enabled.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
workdir
|
Workdir
|
Run artifact paths containing the saved report and metrics. |
required |
summary
|
SafeSynthesizerSummary
|
Final pipeline summary used to construct the scorecard. |
required |
upload_report
|
bool
|
Whether report HTML and artifact egress is permitted. |
required |
Source code in src/nemo_safe_synthesizer/cli/wandb_setup.py
update_wandb_config(cfg=None, additional_configs=None)
¶
Update the wandb config with the given configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cfg
|
SafeSynthesizerParameters | None
|
SafeSynthesizerParameters to log |
None
|
additional_configs
|
dict[str, Any] | None
|
Additional key-value pairs to log |
None
|
Source code in src/nemo_safe_synthesizer/cli/wandb_setup.py
initialize_wandb_run(workdir, resume_job_id=None, cfg=None)
¶
Initialize or resume a wandb run with consistent configuration.
This function handles four cases (in priority order): 1. WandB already initialized - just save the run ID 2. Explicit resume_job_id provided - resume that run (ID or file path) 3. Resume existing run from saved run_id file in workdir 4. Create new run
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
workdir
|
Workdir
|
Workdir structure containing paths for run ID files |
required |
resume_job_id
|
str | None
|
Optional wandb run ID or path to file containing the ID |
None
|
cfg
|
SafeSynthesizerParameters | None
|
Optional SafeSynthesizerParameters to log to wandb config |
None
|
Source code in src/nemo_safe_synthesizer/cli/wandb_setup.py
460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 | |
log_observability_event(event, prefix)
¶
Log an observability event to the currently active wandb run.
Generic sink shared by final training and generation observability paths.
No-op when no wandb run is active (WANDB_MODE=disabled or the pipeline
hasn't called :func:initialize_wandb_run). Errors during summary updates are
swallowed at warning level -- observability is best-effort and a wandb
failure must not break the run.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
event
|
WandbLoggable
|
Any object exposing |
required |
prefix
|
str
|
wandb key namespace for this event's metrics (e.g. |
required |