refactor : 清理工厂和配置系统中的死代码与冗余抽象
- 删除 Registry 中未使用的 category/priority 字段,_entries 简化为直接存储类引用 - 修正 __init_subclass__ 避免叶子类(AutoRegressiveLM 等)创建空注册表 - 删除 5 个工厂的薄 create() 覆写,统一使用 BaseFactory.create(name, *args, **kwargs) - 删除 3 处零调用的 available_types/available_strategies 别名死代码 - 删除零调用的 BaseModelConfig.to_file 死代码 - 将 BaseConfig.from_json/to_json 重命名为 from_file/to_file,消除与子类重复 - 移除两个 inference builder 中总是被覆写的 prompt_tokens=0
This commit is contained in:
@@ -53,15 +53,15 @@ def test_to_dict_roundtrip():
|
||||
assert config2.mask == {"prompt": "mask", "response": "train"}
|
||||
|
||||
|
||||
def test_to_json_from_json(temp_dir):
|
||||
def test_to_file_from_file(temp_dir):
|
||||
config = PipelineConfig(
|
||||
input=InputConfig(sections=_TEXT_SECTIONS),
|
||||
mask={"text": "train"},
|
||||
mask_default="mask",
|
||||
)
|
||||
path = os.path.join(temp_dir, "config.json")
|
||||
config.to_json(path)
|
||||
loaded = PipelineConfig.from_json(path)
|
||||
config.to_file(path)
|
||||
loaded = PipelineConfig.from_file(path)
|
||||
assert loaded.input.sections == _TEXT_SECTIONS
|
||||
assert loaded.mask == {"text": "train"}
|
||||
|
||||
@@ -69,8 +69,8 @@ def test_to_json_from_json(temp_dir):
|
||||
def test_dpo_config_roundtrip(temp_dir):
|
||||
config = make_dpo_chat_config()
|
||||
path = os.path.join(temp_dir, "config.json")
|
||||
config.to_json(path)
|
||||
loaded = PipelineConfig.from_json(path)
|
||||
config.to_file(path)
|
||||
loaded = PipelineConfig.from_file(path)
|
||||
assert loaded.input.sources is not None
|
||||
assert "chosen" in loaded.input.sources
|
||||
assert "rejected" in loaded.input.sources
|
||||
|
||||
@@ -65,7 +65,7 @@ def create_train_config(
|
||||
|
||||
def scheduler_fn(optim):
|
||||
return SchedulerFactory.create(
|
||||
optim, "cosine", warmup_steps=10, lr_decay_steps=10, min_rate=0.05
|
||||
"cosine", optim, warmup_steps=10, lr_decay_steps=10, min_rate=0.05
|
||||
)
|
||||
|
||||
return TrainConfig(
|
||||
|
||||
@@ -102,7 +102,7 @@ def test_gradient_checkpointing_trainer_integration(base_test_env, random_datase
|
||||
|
||||
def scheduler_fn(optim):
|
||||
return SchedulerFactory.create(
|
||||
optim, "cosine", warmup_steps=10, lr_decay_steps=10, min_rate=0.05
|
||||
"cosine", optim, warmup_steps=10, lr_decay_steps=10, min_rate=0.05
|
||||
)
|
||||
|
||||
train_config = TrainConfig(
|
||||
@@ -136,7 +136,7 @@ def test_callback_integration(base_test_env, random_dataset):
|
||||
|
||||
def scheduler_fn(optim):
|
||||
return SchedulerFactory.create(
|
||||
optim, "cosine", warmup_steps=10, lr_decay_steps=10, min_rate=0.05
|
||||
"cosine", optim, warmup_steps=10, lr_decay_steps=10, min_rate=0.05
|
||||
)
|
||||
|
||||
train_config = TrainConfig(
|
||||
|
||||
@@ -16,7 +16,7 @@ def test_early_stopping_simulation(base_test_env, early_stopping_dataset):
|
||||
|
||||
def scheduler_fn(optim):
|
||||
return SchedulerFactory.create(
|
||||
optim, "cosine", warmup_steps=10, lr_decay_steps=10, min_rate=0.05
|
||||
"cosine", optim, warmup_steps=10, lr_decay_steps=10, min_rate=0.05
|
||||
)
|
||||
|
||||
train_config = TrainConfig(
|
||||
|
||||
@@ -36,8 +36,8 @@ def test_schedule_factory_random_configs():
|
||||
min_rate = params["min_rate"]
|
||||
lr_decay_steps = total_steps - warmup_steps
|
||||
scheduler = SchedulerFactory.create(
|
||||
optimizer,
|
||||
schedule_type,
|
||||
optimizer,
|
||||
warmup_steps=warmup_steps,
|
||||
lr_decay_steps=lr_decay_steps,
|
||||
min_rate=min_rate,
|
||||
@@ -52,8 +52,8 @@ def test_schedule_factory_random_configs():
|
||||
t_mult = params["t_mult"]
|
||||
min_rate = params["min_rate"]
|
||||
scheduler = SchedulerFactory.create(
|
||||
optimizer,
|
||||
schedule_type,
|
||||
optimizer,
|
||||
warmup_steps=warmup_steps,
|
||||
cycle_length=cycle_length,
|
||||
t_mult=t_mult,
|
||||
@@ -103,8 +103,8 @@ def test_schedule_factory_edge_cases():
|
||||
min_rate = params["min_rate"]
|
||||
lr_decay_steps = total_steps - warmup_steps
|
||||
scheduler = SchedulerFactory.create(
|
||||
optimizer,
|
||||
"cosine",
|
||||
optimizer,
|
||||
warmup_steps=warmup_steps,
|
||||
lr_decay_steps=lr_decay_steps,
|
||||
min_rate=min_rate,
|
||||
@@ -129,8 +129,8 @@ def test_schedule_factory_state_persistence():
|
||||
min_rate = 0.1
|
||||
lr_decay_steps = total_steps - warmup_steps
|
||||
scheduler = SchedulerFactory.create(
|
||||
optimizer,
|
||||
"cosine",
|
||||
optimizer,
|
||||
warmup_steps=warmup_steps,
|
||||
lr_decay_steps=lr_decay_steps,
|
||||
min_rate=min_rate,
|
||||
@@ -146,8 +146,8 @@ def test_schedule_factory_state_persistence():
|
||||
|
||||
# Create new scheduler with same parameters
|
||||
new_scheduler = SchedulerFactory.create(
|
||||
optimizer,
|
||||
"cosine",
|
||||
optimizer,
|
||||
warmup_steps=warmup_steps,
|
||||
lr_decay_steps=lr_decay_steps,
|
||||
min_rate=min_rate,
|
||||
|
||||
Reference in New Issue
Block a user