MCPcopy Create free account
hub / github.com/pytorch/pytorch / test_upload_checkpoint

Method test_upload_checkpoint

caffe2/python/checkpoint_test.py:203–239  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

201 shutil.rmtree(tmpdir)
202
203 def test_upload_checkpoint(self):
204 try:
205 tmpdir = tempfile.mkdtemp()
206 upload_dir = os.path.join(tmpdir, "upload")
207 os.mkdir(upload_dir)
208 num_nodes = 3
209
210 # The uploaded files do not exist yet.
211 for node_id in range(num_nodes):
212 node_name = 'trainer_%d' % node_id
213 upload_path = os.path.join(upload_dir, node_name)
214 self.assertFalse(os.path.exists(upload_path))
215
216 # Create and run the job runner.
217 for node_id in range(3):
218 ws = workspace.C.Workspace()
219 session = LocalSession(ws)
220 checkpoint = MultiNodeCheckpointManager(tmpdir, 'minidb')
221 with Cluster():
222 with Job() as job:
223 build_pipeline(node_id)
224 job.compile(LocalSession)
225 local_upload_builder = UploadToLocalFile(upload_dir)
226 job_runner = JobRunner(
227 job, checkpoint,
228 upload_task_group_builder=local_upload_builder)
229 num_epochs = job_runner.train(session)
230 self.assertEqual(num_epochs, len(EXPECTED_TOTALS))
231
232 # The uploaded files should exist now.
233 for node_id in range(num_nodes):
234 node_name = 'trainer_%d' % node_id
235 upload_path = os.path.join(upload_dir, node_name)
236 self.assertTrue(os.path.exists(upload_path))
237
238 finally:
239 shutil.rmtree(tmpdir)
240
241 def test_ckpt_save_failure(self):
242 num_nodes = 3

Callers

nothing calls this directly

Calls 12

trainMethod · 0.95
LocalSessionClass · 0.90
ClusterClass · 0.90
JobClass · 0.90
JobRunnerClass · 0.90
build_pipelineFunction · 0.85
UploadToLocalFileClass · 0.85
rangeFunction · 0.50
joinMethod · 0.45
compileMethod · 0.45
assertEqualMethod · 0.45

Tested by

no test coverage detected