Test both mode with LoRA request.
(self)
| 1351 | |
| 1352 | class TestTrainerLoRA(BaseTrainerCase): |
| 1353 | def test_trainer(self): |
| 1354 | """Test both mode with LoRA request.""" |
| 1355 | self.config.buffer.explorer_input.taskset = get_unittest_dataset_config("gsm8k") |
| 1356 | self.config.buffer.explorer_input.eval_tasksets.append( |
| 1357 | get_unittest_dataset_config("gsm8k", "test") |
| 1358 | ) |
| 1359 | self.config.buffer.explorer_input.eval_tasksets[0].repeat_times = 8 |
| 1360 | self.config.model.model_path = get_model_path() |
| 1361 | self.config.algorithm.algorithm_type = "grpo" |
| 1362 | self.config.algorithm.advantage_fn = "grpo" |
| 1363 | self.config.algorithm.kl_loss_fn = "none" |
| 1364 | self.config.algorithm.repeat_times = 4 |
| 1365 | self.config.buffer.batch_size = 4 |
| 1366 | self.config.buffer.total_steps = 2 |
| 1367 | self.config.cluster.node_num = 1 |
| 1368 | self.config.cluster.gpu_per_node = 4 |
| 1369 | self.config.explorer.eval_interval = 2 |
| 1370 | self.config.model.lora_configs = [get_lora_config()] |
| 1371 | self.config.synchronizer.sync_method = SyncMethod.CHECKPOINT |
| 1372 | self.config.synchronizer.sync_interval = 2 |
| 1373 | self.config.trainer.save_interval = 2 |
| 1374 | self.config.check_and_update() |
| 1375 | both(self.config) |
| 1376 | # check metrics are available |
| 1377 | parser = TensorBoardParser(os.path.join(self.config.monitor.cache_dir, "tensorboard")) |
| 1378 | rollout_metrics = parser.metric_list("rollout") |
| 1379 | self.assertGreater(len(rollout_metrics), 0) |
| 1380 | self.assertEqual(parser.metric_max_step(rollout_metrics[0]), 2) |
| 1381 | actor_metrics = parser.metric_list("actor") |
| 1382 | self.assertGreater(len(actor_metrics), 0) |
| 1383 | self.assertEqual(parser.metric_max_step(actor_metrics[0]), 2) |
| 1384 | time_metrics = parser.metric_list("time") |
| 1385 | self.assertGreater(len(time_metrics), 0) |
| 1386 | self.assertEqual(parser.metric_max_step(time_metrics[0]), 2) |
| 1387 | ray.shutdown(_exiting_interpreter=True) |
| 1388 | # check save lastest checkpoint |
| 1389 | checkpoint_step_2, step_num = get_checkpoint_dir_with_step_num( |
| 1390 | checkpoint_root_path=self.config.checkpoint_job_dir, |
| 1391 | trainer_type=self.config.trainer.trainer_type, |
| 1392 | ) |
| 1393 | self.assertGreater(len(os.listdir(os.path.join(checkpoint_step_2, "actor"))), 0) |
| 1394 | self.assertGreater( |
| 1395 | len(os.listdir(os.path.join(checkpoint_step_2, "actor", "lora_adapter"))), 0 |
| 1396 | ) |
| 1397 | self.assertEqual(step_num, 2) |
| 1398 | |
| 1399 | # test bench mode |
| 1400 | ray.init(ignore_reinit_error=True, namespace=self.config.ray_namespace) |
| 1401 | self.config.mode = "bench" |
| 1402 | self.config.synchronizer.sync_method = SyncMethod.CHECKPOINT |
| 1403 | self.config.explorer.bench_on_latest_checkpoint = False |
| 1404 | self.config.check_and_update() |
| 1405 | bench(self.config) |
| 1406 | parser = TensorBoardParser(os.path.join(self.config.monitor.cache_dir, "tensorboard")) |
| 1407 | for prefix in ["eval", "bench"]: |
| 1408 | gsm8k_metrics = parser.metric_list(f"{prefix}/gsm8k") |
| 1409 | self.assertGreater(len(gsm8k_metrics), 0, f"{prefix}/gsm8k metrics not found") |
| 1410 | repeat_times, k_list = 8, [2, 4, 8] |
nothing calls this directly
no test coverage detected