MCPcopy Create free account
hub / github.com/Pints-AI/1.5-Pints / save_hyperparameters

Function save_hyperparameters

lit_gpt/utils.py:467–488  ·  view source on GitHub ↗

Captures the CLI parameters passed to `function` without running `function` and saves them to the checkpoint.

(function: callable, checkpoint_dir: Path)

Source from the content-addressed store, hash-verified

465
466
467def save_hyperparameters(function: callable, checkpoint_dir: Path) -> None:
468 """Captures the CLI parameters passed to `function` without running `function` and saves them to the checkpoint."""
469 from jsonargparse import capture_parser
470
471 # TODO: Make this more robust
472 # This hack strips away the subcommands from the top-level CLI
473 # to parse the file as if it was called as a script
474 known_commands = [
475 ('finetune', 'full'),
476 ('finetune', 'lora'),
477 ('finetune', 'adapter'),
478 ('finetune', 'adapter_v2'),
479 ('pretrain',),
480 ]
481 for known_command in known_commands:
482 unwanted = slice(1, 1 + len(known_command))
483 if tuple(sys.argv[unwanted]) == known_command:
484 sys.argv[unwanted] = []
485
486 parser = capture_parser(lambda: CLI(function))
487 config = parser.parse_args()
488 parser.save(config, checkpoint_dir / 'hyperparameters.yaml', overwrite=True)
489
490
491def save_config(config: 'Config', checkpoint_dir: Path) -> None:

Callers 2

mainFunction · 0.90
fitFunction · 0.90

Calls 2

CLIFunction · 0.85
saveMethod · 0.45

Tested by

no test coverage detected