File size: 985 Bytes
8014d08 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# main.py
from lightning.pytorch.cli import LightningCLI
from lightning.pytorch.callbacks import ModelCheckpoint
from lightning.fabric import seed_everything
from Algorithms import ActorCritic
from Tasks import TwentyQuestions
import torch
torch.backends.cuda.matmul.allow_tf32 = True # 启用 TF32 加速
torch.backends.cudnn.allow_tf32 = True
from torch.cuda.amp import GradScaler # 如果用 AMP
seed_everything(42)
def cli_main():
checkpoint_callback = ModelCheckpoint(
dirpath="models",
every_n_train_steps=200,
every_n_epochs=0,
save_top_k=1,
save_last=True # 同时保存最后一个模型
)
cli = LightningCLI(
save_config_kwargs={"overwrite": True},
trainer_defaults={ # 添加 trainer 默认配置
"callbacks": [checkpoint_callback],
"limit_val_batches": 0,
"val_check_interval": None
}
)
exit(0)
if __name__ == "__main__":
cli_main() |