feat(tests): 改进测试环境配置与设备管理

This commit is contained in:
2025-10-04 12:12:42 +08:00
parent 465a1a9373
commit e7d29ca2d5
7 changed files with 13 additions and 16 deletions
+6 -4
View File
@@ -16,8 +16,9 @@ from khaosz.trainer.data_util import *
matplotlib.use("Agg")
@pytest.fixture
def base_test_env():
test_dir = tempfile.mkdtemp()
def base_test_env(request: pytest.FixtureRequest):
func_name = request.function.__name__
test_dir = tempfile.mkdtemp(prefix=f"{func_name}_")
config_path = os.path.join(test_dir, "config.json")
n_dim_choices = [8, 16, 32]
@@ -41,12 +42,13 @@ def base_test_env():
with open(config_path, 'w') as f:
json.dump(config, f)
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
transformer_config = TransformerConfig().load(config_path)
model = Transformer(transformer_config)
model = Transformer(transformer_config).to(device=device)
tokenizer = BpeTokenizer()
yield {
"device": device,
"test_dir": test_dir,
"config_path": config_path,
"transformer_config": transformer_config,