llm.initialize
Utilities for initializing training environments.
These utilities are used by the training scripts in
llm.trainers
.
get_default_parser
¶
get_default_parser(
prog: str | None = None,
description: str | None = None,
usage: str | None = None,
) -> ArgumentParser
Get the default argument parser to be used with initialize_from_args()
.
Parameters:
-
prog
(str | None
, default:None
) –Optional name of the program.
-
description
(str | None
, default:None
) –Optional description of the program.
-
usage
(str | None
, default:None
) –Optional program usage.
Returns:
-
ArgumentParser
–Parser which you can append your own arguments to.
Source code in llm/initialize.py
initialize
¶
initialize(
*,
debug: bool = False,
loglevel: int | str = "INFO",
logfile: Path | str | None = None,
seed: int | None = None,
rich: bool = False
) -> None
Initialize the distributed context.
Perform the following: 1) initialize logging, 2) initialized torch distributed, and 3) set the cuda device is available.
Parameters:
-
debug
(bool
, default:False
) –Initialize torch distributed for debugging (single worker).
-
loglevel
(int | str
, default:'INFO'
) –Minimum logging level.
-
logfile
(Path | str | None
, default:None
) –Log filepath.
-
seed
(int | None
, default:None
) –Random seed.
-
rich
(bool
, default:False
) –Use rich formatting for stdout logging.
Source code in llm/initialize.py
initialize_from_args
¶
Load config and initialize from args.
Example
import sys
from typing import Sequence
from llm.initialize import get_default_parser
from llm.initialize import initialize_from_args
def main(argv: Sequence[str] | None = None) -> int:
argv = argv if argv is not None else sys.argv[1:]
parser = get_default_parser()
args = parser.parse_args(argv)
config = initialize_from_args(args)
# Rest of your training script
if __name__ == '__main__':
raise SystemExit(main())