Skip to content

train

configure_test_parser

Add a testing parser to an existing argparser.

Parameters:

Name Type Description Default
subparsers _SubParsersAction

The parser object to be appended to.

required
Source code in fastestimator/fastestimator/cli/train.py
def configure_test_parser(subparsers: argparse._SubParsersAction) -> None:
    """Add a testing parser to an existing argparser.

    Args:
        subparsers: The parser object to be appended to.
    """
    parser = subparsers.add_parser('test',
                                   description='Test a FastEstimator model',
                                   formatter_class=argparse.ArgumentDefaultsHelpFormatter,
                                   allow_abbrev=False)
    # use an argument group for required flag arguments since otherwise they will show up as optional in the help
    parser.add_argument('entry_point', type=str, help='The path to the model python file')
    parser.add_argument('--hyperparameters',
                        dest='hyperparameters_json',
                        type=str,
                        help="The path to the hyperparameters JSON file")
    parser.add_argument('--eager',
                        type=literal_eval,
                        help="Eager setting, can be True or False",
                        choices=[True, False],
                        default=False)
    parser.add_argument('--summary', type=str, help="Experiment name", default=None)
    parser.add_argument_group(
        'hyperparameter arguments',
        'Arguments to be passed through to the get_estimator() call. \
        Examples might look like --epochs <int>, --batch_size <int>, --optimizer <str>, etc...')
    parser.set_defaults(func=test)

configure_train_parser

Add a training parser to an existing argparser.

Parameters:

Name Type Description Default
subparsers _SubParsersAction

The parser object to be appended to.

required
Source code in fastestimator/fastestimator/cli/train.py
def configure_train_parser(subparsers: argparse._SubParsersAction) -> None:
    """Add a training parser to an existing argparser.

    Args:
        subparsers: The parser object to be appended to.
    """
    parser = subparsers.add_parser('train',
                                   description='Train a FastEstimator model',
                                   formatter_class=argparse.ArgumentDefaultsHelpFormatter,
                                   allow_abbrev=False)
    # use an argument group for required flag arguments since otherwise they will show up as optional in the help
    parser.add_argument('entry_point', type=str, help='The path to the model python file')
    parser.add_argument('--hyperparameters',
                        dest='hyperparameters_json',
                        type=str,
                        help="The path to the hyperparameters JSON file")
    parser.add_argument('--warmup',
                        type=literal_eval,
                        help="Warmup setting, can be True or False",
                        choices=[True, False],
                        default=True)
    parser.add_argument('--eager',
                        type=literal_eval,
                        help="Eager setting, can be True or False",
                        choices=[True, False],
                        default=False)
    parser.add_argument('--summary', type=str, help="Experiment name", default=None)
    parser.add_argument_group(
        'hyperparameter arguments',
        'Arguments to be passed through to the get_estimator() call. \
        Examples might look like --epochs <int>, --batch_size <int>, --optimizer <str>, etc...')
    parser.set_defaults(func=train)

test

Load an Estimator from a file and invoke its .test() method.

Parameters:

Name Type Description Default
args Dict[str, Any]

A dictionary containing location of the FE file under the 'entry_point' key, as well as an optional 'hyperparameters_json' key if the user is storing their parameters in a file.

required
unknown Optional[List[str]]

The remainder of the command line arguments to be passed along to the get_estimator() method.

required
Source code in fastestimator/fastestimator/cli/train.py
def test(args: Dict[str, Any], unknown: Optional[List[str]]) -> None:
    """Load an Estimator from a file and invoke its .test() method.

    Args:
        args: A dictionary containing location of the FE file under the 'entry_point' key, as well as an optional
            'hyperparameters_json' key if the user is storing their parameters in a file.
        unknown: The remainder of the command line arguments to be passed along to the get_estimator() method.
    """
    estimator = _get_estimator(args, unknown)
    estimator.test(summary=args['summary'], eager=args['eager'])

train

Load an Estimator from a file and invoke its .fit() method.

Parameters:

Name Type Description Default
args Dict[str, Any]

A dictionary containing location of the FE file under the 'entry_point' key, as well as an optional 'hyperparameters_json' key if the user is storing their parameters in a file.

required
unknown Optional[List[str]]

The remainder of the command line arguments to be passed along to the get_estimator() method.

required
Source code in fastestimator/fastestimator/cli/train.py
def train(args: Dict[str, Any], unknown: Optional[List[str]]) -> None:
    """Load an Estimator from a file and invoke its .fit() method.

    Args:
        args: A dictionary containing location of the FE file under the 'entry_point' key, as well as an optional
            'hyperparameters_json' key if the user is storing their parameters in a file.
        unknown: The remainder of the command line arguments to be passed along to the get_estimator() method.
    """
    estimator = _get_estimator(args, unknown)
    estimator.fit(warmup=args['warmup'], eager=args['eager'], summary=args['summary'])