MCPcopy Create free account
hub / github.com/pytorch/tutorials / run_training_job

Function run_training_job

intermediate_source/mnist_train_nas.py:131–167  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

129
130
131def run_training_job():
132
133 mnist_model = MnistModel()
134
135 # Initialize a trainer (don't log anything since things get so slow...)
136 trainer = Trainer(
137 logger=False,
138 max_epochs=args.epochs,
139 enable_progress_bar=False,
140 deterministic=True, # Do we want a bit of noise?
141 default_root_dir=args.log_path,
142 )
143
144 logger = pl_loggers.TensorBoardLogger(args.log_path)
145
146 print(f"Logging to path: {args.log_path}.")
147
148 # Train the model and log time ⚡
149 start = time.time()
150 trainer.fit(model=mnist_model)
151 end = time.time()
152 train_time = end - start
153 logger.log_metrics({"train_time": end - start})
154
155 # Compute the validation accuracy once and log the score
156 with io.capture_output() as captured:
157 val_accuracy = trainer.validate()[0]["val_acc"]
158 logger.log_metrics({"val_acc": val_accuracy})
159
160 # Log the number of model parameters
161 num_params = trainer.model.num_params
162 logger.log_metrics({"num_params": num_params})
163
164 logger.save()
165
166 # Print outputs
167 print(f"train time: {train_time}, val acc: {val_accuracy}, num_params: {num_params}")
168
169
170if __name__ == "__main__":

Callers 1

mnist_train_nas.pyFile · 0.85

Calls 2

MnistModelClass · 0.85
saveMethod · 0.80

Tested by

no test coverage detected