def create_trial_instance(trial_def: Type[det.Trial]) -> None: with tempfile.TemporaryDirectory() as td: trial_instance = experimental.create_trial_instance( trial_def=trial_def, config={"hyperparameters": {"global_batch_size": det.Constant(16)}}, checkpoint_dir=td, ) check.check_isinstance(trial_instance, det.Trial)
dest="config", help="Specifies Determined Experiment configuration.", default="{}", ) parser.add_argument("--local", action="store_true", help="Specifies local mode") parser.add_argument("--test", action="store_true", help="Specifies test mode") parser.add_argument( "--use-fit", action="store_true", help="If true, uses model.fit() instead of model.fit_generator()", ) args = parser.parse_args() config = { "hyperparameters": { "global_batch_size": det.Constant(value=32), "dense1": det.Constant(value=128), }, "searcher": {"name": "single", "metric": "val_accuracy", "max_steps": 40}, } config.update(json.loads(args.config)) context = init(config, local=args.local, test=args.test, context_dir=str(pathlib.Path.cwd())) train_images, train_labels = data.load_training_data() train_images = train_images / 255.0 train_data = _ArrayLikeAdapter( x=train_images, y=train_labels, batch_size=context.get_per_slot_batch_size() ) test_images, test_labels = data.load_validation_data()
) return model def build_training_data_loader(self): return np.zeros(1), np.zeros(1) def build_validation_data_loader(self): return np.zeros(1), np.zeros(1) if __name__ == "__main__": experimental.create( trial_def=RuntimeErrorTrial, config={ "description": "keras_runtime_error", "hyperparameters": { "global_batch_size": det.Constant(1) }, "searcher": { "metric": "accuracy" }, "data_layer": { "type": "lfs", "container_storage_path": "/tmp" }, }, local=True, test=True, context_dir=str(pathlib.Path.cwd()), )
parser = argparse.ArgumentParser() parser.add_argument( "--config", dest="config", help="Specifies Determined Experiment configuration.", default="{}", ) parser.add_argument( "--mode", dest="mode", help="Specifies local mode or cluster mode.", default="cluster" ) args = parser.parse_args() config = { "hyperparameters": { "learning_rate": det.Log(-4.0, -2.0, 10), "global_batch_size": det.Constant(64), "hidden_layer_1": det.Constant(250), "hidden_layer_2": det.Constant(250), "hidden_layer_3": det.Constant(250), "dropout": det.Double(0.0, 0.5), }, "searcher": { "name": "single", "metric": "accuracy", "max_steps": 10, "smaller_is_better": False, }, } config.update(json.loads(args.config)) context = estimator.init(
) parser.add_argument("--mode", dest="mode", help="Specifies local mode or cluster mode.", default="cluster") args = parser.parse_args() config = { "data": { "url": "https://s3-us-west-2.amazonaws.com/determined-ai-test-data/pytorch_mnist.tar.gz" }, "hyperparameters": { "learning_rate": det.Log(minval=-3.0, maxval=-1.0, base=10), "dropout": det.Double(minval=0.2, maxval=0.8), "global_batch_size": det.Constant(value=64), "n_filters1": det.Constant(value=32), "n_filters2": det.Constant(value=32), }, "searcher": { "name": "single", "metric": "validation_error", "max_steps": 20, "smaller_is_better": True, }, } config.update(json.loads(args.config)) experimental.create( trial_def=model_def.MNistTrial, config=config,
action="store_true", help="Specifies local mode") parser.add_argument("--test", action="store_true", help="Specifies test mode") args = parser.parse_args() dataset_url = ( "https://determined-ai-public-datasets.s3-us-west-2.amazonaws.com/" "PennFudanPed/PennFudanPed.zip") config = { "data": { "url": dataset_url }, "hyperparameters": { "learning_rate": det.Constant(value=0.005), "momentum": det.Constant(value=0.9), "weight_decay": det.Constant(value=0.0005), "global_batch_size": det.Constant(value=2), }, "batches_per_step": 1, "searcher": { "name": "single", "metric": "val_avg_iou", "max_steps": 16, "smaller_is_better": False, }, } config.update(json.loads(args.config)) experimental.create(
dest="mode", help="Specifies test mode or submit mode.", default="submit") args = parser.parse_args() config = { "description": "Resnet50 Imagenet TF Keras", "searcher": { "name": "single", "metric": "val_loss", "max_steps": 1, "smaller_is_better": True, }, "min_validation_period": 1, "hyperparameters": { "global_batch_size": det.Constant(value=32), "learning_rate": det.Constant(value=0.1), }, } ctx = keras.init(config=config, mode=experimental.Mode(args.mode), context_dir=str(pathlib.Path.cwd())) lr_schedule = ctx.get_hparam("learning_rate") if ctx.get_data_config().get("use_tensor_lr", False): lr_schedule = common.PiecewiseConstantDecayWithWarmup( batch_size=ctx.get_per_slot_batch_size(), epoch_size=imagenet_preprocessing.NUM_IMAGES["train"], warmup_epochs=common.LR_SCHEDULE[0][1], boundaries=[p[1] for p in common.LR_SCHEDULE[1:]], multipliers=[p[0] for p in common.LR_SCHEDULE],
model = keras.Sequential([keras.layers.Dense(10)]) model = self.context.wrap_model(model) model.compile( optimizer="adam", loss=tf.keras.losses.SparseCategoricalCrossentropy(from_logits=True), metrics=[ tf.keras.metrics.Accuracy() ], # ERR: this is the wrong accuracy, should be SparseCategoricalAccuracy ) return model def build_training_data_loader(self): return np.zeros(1), np.zeros(1) def build_validation_data_loader(self): return np.zeros(1), np.zeros(1) if __name__ == "__main__": experimental.create( trial_def=RuntimeErrorTrial, config={ "description": "keras_runtime_error", "hyperparameters": {"global_batch_size": det.Constant(1)}, "searcher": {"metric": "accuracy"}, "data_layer": {"type": "lfs", "container_storage_path": "/tmp"}, }, mode=experimental.Mode.LOCAL, context_dir=str(pathlib.Path.cwd()), )
"metric": "acc", "max_length": { "batches": 400, }, "smaller_is_better": True, }, "data": { "data_dir": "/tmp/data", "task": "MRPC", "model_name_or_path": "bert-base-uncased", "output_mode": "classification", "path_to_mrpc": "", "download_data": True, }, "hyperparameters": { "global_batch_size": det.Constant(value=24), "model_type": det.Constant(value="bert"), "learning_rate": det.Constant(value=0.00002), "lr_scheduler_epoch_freq": det.Constant(value=1), "adam_epsilon": det.Constant(value=1e-8), "weight_decay": det.Constant(value=0), "num_warmup_steps": det.Constant(value=0), "num_training_steps": det.Constant(value=459), "max_seq_length": det.Constant(value=128), }, } experimental.create( trial_def=model_def.BertPytorch, mode=experimental.Mode(args.mode), context_dir=str(pathlib.Path.cwd()),
default="{}", ) parser.add_argument("--mode", dest="mode", help="Specifies local mode or cluster mode.", default="cluster") parser.add_argument( "--use-fit", action="store_true", help="If true, uses model.fit() instead of model.fit_generator()", ) args = parser.parse_args() config = { "hyperparameters": { "global_batch_size": det.Constant(value=32), "kernel_size": det.Constant(value=3), "dropout": det.Double(minval=0.0, maxval=0.5), "activation": det.Constant(value="relu"), }, "searcher": { "name": "single", "metric": "val_accuracy", "max_steps": 40 }, } config.update(json.loads(args.config)) context = keras.init(config, mode=experimental.Mode(args.mode), context_dir=str(pathlib.Path.cwd()))