MCPcopy Create free account
hub / github.com/agentscope-ai/Trinity-RFT / test_trainer

Method test_trainer

tests/trainer/trainer_test.py:1314–1345  ·  view source on GitHub ↗

Test SFT mode with multi-modal data.

(self)

Source from the content-addressed store, hash-verified

1312
1313class TestMultiModalSFT(BaseTrainerCase):
1314 def test_trainer(self):
1315 """Test SFT mode with multi-modal data."""
1316 self.config.mode = "train"
1317 self.config.buffer.trainer_input.experience_buffer = get_unittest_dataset_config(
1318 "geometry_sft"
1319 ) # Total 8 tasks
1320 self.config.model.model_path = get_vision_language_model_path()
1321 self.config.algorithm.algorithm_type = "sft"
1322 self.config.algorithm.policy_loss_fn = "sft"
1323 self.config.algorithm.policy_loss_fn_args = {}
1324 self.config.algorithm.kl_loss_fn = "none"
1325 self.config.algorithm.entropy_loss_fn = "none"
1326 self.config.buffer.train_batch_size = 4
1327 self.config.buffer.total_epochs = 1
1328 self.config.trainer.save_interval = 2
1329 self.config.check_and_update()
1330 train(self.config)
1331 # check metrics are available
1332 parser = TensorBoardParser(os.path.join(self.config.monitor.cache_dir, "tensorboard"))
1333 actor_metrics = parser.metric_list("actor")
1334 self.assertGreater(len(actor_metrics), 0)
1335 self.assertEqual(parser.metric_max_step(actor_metrics[0]), 2)
1336 time_metrics = parser.metric_list("time")
1337 self.assertGreater(len(time_metrics), 0)
1338 self.assertEqual(parser.metric_max_step(time_metrics[0]), 2)
1339 # check save lastest checkpoint
1340 checkpoint_step_2, step_num = get_checkpoint_dir_with_step_num(
1341 checkpoint_root_path=self.config.checkpoint_job_dir,
1342 trainer_type=self.config.trainer.trainer_type,
1343 )
1344 self.assertGreater(len(os.listdir(os.path.join(checkpoint_step_2, "actor"))), 0)
1345 self.assertEqual(step_num, 2)
1346
1347 def tearDown(self):
1348 # remove dir only when the test passed

Callers

nothing calls this directly

Calls 8

metric_listMethod · 0.95
metric_max_stepMethod · 0.95
trainFunction · 0.90
TensorBoardParserClass · 0.90
check_and_updateMethod · 0.80

Tested by

no test coverage detected