This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| data = cudf.read_csv(data_dir+'HIGGS.csv', names=col_names, dtype=dtypes_ls) | |
| X_train, X_test, y_train, y_test = train_test_split(data, 'label', train_size=0.70) | |
| hyperparams={ | |
| 'n_estimators' : args.n_estimators, | |
| 'max_depth' : args.max_depth, | |
| 'n_bins' : args.n_bins, | |
| 'split_criterion' : args.split_criterion, | |
| 'split_algo' : args.split_algo, | |
| 'bootstrap' : args.bootstrap, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| parser = argparse.ArgumentParser() | |
| # Hyper-parameters | |
| parser.add_argument('--n_estimators', type=int, default=20) | |
| parser.add_argument('--max_depth', type=int, default=16) | |
| parser.add_argument('--n_bins', type=int, default=8) | |
| parser.add_argument('--split_criterion', type=int, default=0) | |
| parser.add_argument('--split_algo', type=int, default=0) | |
| parser.add_argument('--bootstrap', type=bool, default=True) | |
| parser.add_argument('--bootstrap_features', type=bool, default=False) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| hyperparams={ | |
| 'n_estimators' : 15, | |
| 'max_depth' : 5, | |
| 'n_bins' : 8, | |
| 'split_criterion' : 0, # GINI:0, ENTROPY:1 | |
| 'split_algo' : 0, # HIST:0 GLOBAL_QUANTILE:1 | |
| 'bootstrap' : 0, # true: sample with replacement, false: sample without replacement | |
| 'bootstrap_features' : 0, # true: sample with replacement, false: sample without replacement | |
| 'max_leaves' : -1, # unlimited leaves | |
| 'max_features' : 0.2, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from sagemaker.estimator import Estimator | |
| train_instance_type = 'local_gpu' | |
| local_data_dir = 'file://./dataset' | |
| rapids_estimator = Estimator(image_name='sagemaker-rapids:latest', | |
| role=role, | |
| train_instance_count=1, | |
| train_instance_type=train_instance_type, | |
| hyperparameters=hyperparams, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from sagemaker.tuner import IntegerParameter, CategoricalParameter, ContinuousParameter, HyperparameterTuner | |
| hyperparameter_ranges = { | |
| 'n_estimators' : IntegerParameter(10, 200), | |
| 'max_depth' : IntegerParameter(1, 22), | |
| 'n_bins' : IntegerParameter(5, 24), | |
| 'split_criterion' : CategoricalParameter([0, 1]), | |
| 'split_algo' : CategoricalParameter([0, 1]), | |
| 'bootstrap' : CategoricalParameter([True, False]), | |
| 'bootstrap_features' : CategoricalParameter([True, False]), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from sagemaker.estimator import Estimator | |
| train_instance_type = 'ml.p3.2xlarge' | |
| rapids_estimator = Estimator(image_name=image, | |
| role=role, | |
| train_instance_count=1, | |
| train_instance_type=train_instance_type, | |
| hyperparameters=hyperparams, | |
| metric_definitions=[{'Name': 'test_acc', 'Regex': 'test_acc: ([0-9\\.]+)'}]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| tuner = HyperparameterTuner(rapids_estimator, | |
| objective_metric_name='test_acc', | |
| hyperparameter_ranges=hyperparameter_ranges, | |
| strategy='Bayesian', | |
| max_jobs=1, | |
| max_parallel_jobs=1, | |
| objective_type='Maximize', | |
| metric_definitions=[{'Name': 'test_acc', 'Regex': 'test_acc: ([0-9\\.]+)'}]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| s3_data_dir = sagemaker_session.upload_data(path='dataset', key_prefix='dataset/higgs-dataset') | |
| job_name = 'rapidsHPO' + time.strftime('%Y-%m-%d-%H-%M-%S-%j', time.gmtime()) | |
| tuner.fit({'dataset': s3_data_dir}, job_name=job_name) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| callbacks = [] | |
| callbacks.append(hvd.callbacks.BroadcastGlobalVariablesCallback(0)) | |
| callbacks.append(hvd.callbacks.MetricAverageCallback()) | |
| callbacks.append(hvd.callbacks.LearningRateWarmupCallback(warmup_epochs=5, verbose=1)) | |
| callbacks.append(tf.keras.callbacks.ReduceLROnPlateau(patience=10, verbose=1)) | |
| if hvd.rank() == 0: | |
| callbacks.append(ModelCheckpoint(args.output_data_dir + '/checkpoint-{epoch}.h5')) | |
| logdir = args.output_data_dir + '/' + datetime.now().strftime("%Y%m%d-%H%M%S") | |
| callbacks.append(TensorBoard(log_dir=logdir)) | |
| callbacks.append(Sync2S3(logdir=logdir, s3logdir=tensorboard_logs)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| history = model.fit(train_dataset, | |
| steps_per_epoch = (NUM_TRAIN_IMAGES // batch_size) // size, | |
| validation_data = val_dataset, | |
| validation_steps = (NUM_VALID_IMAGES // batch_size) // size, | |
| verbose = 1 if hvd.rank() == 0 else 0, | |
| epochs = epochs, callbacks=callbacks) |
OlderNewer