TheDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/Antisource/heronaisec/llms.txt
Use this file to discover all available pages before exploring further.
utils module provides the infrastructure glue that holds experiment scripts together. It contains only infrastructure code — no attack logic, training logic, or evaluation logic belongs here. The functions in this module are used at the outermost layer of an experiment: loading the YAML configuration, seeding all random number generators for reproducibility, selecting the compute device, and creating a uniquely timestamped output directory tree before any training begins.
Functions
load_config()
Load an experiment configuration from a YAML file usingyaml.safe_load().
Accepts either a str or a pathlib.Path as the config path. The file is opened with UTF-8 encoding and parsed with yaml.safe_load(), which prevents arbitrary Python object deserialisation. The returned dictionary maps directly to the structure of the YAML file and is typically passed to create_run_directory() and unpacked into training hyper-parameters.
Path to the YAML configuration file. Both absolute and relative paths are accepted.
A plain Python dictionary representing the parsed YAML contents.
configs/baseline.yaml):
seed_everything()
Seed all supported random number generators for reproducible experiments. Callsaccelerate.utils.set_seed(seed), which internally seeds Python’s built-in random module, NumPy, and PyTorch (both CPU and all CUDA devices). Call this function at the very start of an experiment script, before any dataset shuffling, model initialisation, or training.
The integer seed value. Use the same seed across all experiment runs you intend to compare.
Returns
None.seed_everything() uses accelerate.utils.set_seed() rather than setting each RNG manually, which ensures compatibility with distributed training scenarios where per-process seeds need to be offset consistently.get_device()
Select the best available compute device. Returnstorch.device("cuda") if CUDA is available, otherwise torch.device("cpu"). Move models and tensors to the returned device to ensure GPU acceleration is used when available.
torch.device("cuda") if torch.cuda.is_available() is True, otherwise torch.device("cpu").ensure_dir()
Create a directory (and any missing parents) if it does not already exist. Equivalent tomkdir -p. Safe to call multiple times on the same path — if the directory already exists, the call is a no-op. Returns the resolved Path object for convenient chaining.
The directory path to create. Intermediate parent directories are created automatically.
The input path coerced to a
pathlib.Path object. The directory is guaranteed to exist after this call.timestamp()
Return a filesystem-safe timestamp string representing the current local time. Formats the current datetime as"%Y%m%d_%H%M%S" (e.g. "20260719_113522"). Used by create_run_directory() to make each experiment run’s output directory unique. Calling this function twice in the same second returns the same string, so it should only be called once per run at startup.
A string of the form
"YYYYMMDD_HHMMSS".create_run_directory()
Create a uniquely timestamped output directory tree for a single experiment run. Constructs the path{output_dir}/{name}/{timestamp}/ from the "experiment" section of the config dictionary, then creates three fixed subdirectories inside it:
checkpoints/— model checkpoint filesfigures/— saved plotslogs/— training logs
mkdir(parents=True, exist_ok=True). The function returns the run-level directory path so that downstream code can build sub-paths relative to it.
The parsed experiment configuration dictionary. Must contain a nested
"experiment" key with the following fields:config["experiment"]["output_dir"]— root results directory (e.g."results")config["experiment"]["name"]— experiment name used as a subdirectory (e.g."baseline")
The path to the newly created run directory, e.g.
Path("results/baseline/20260719_113522").create_run_directory():