feat(utils): 配置继承、注册表、日志与 Nvidia GPU 守卫

- config: yaml `_base_` 继承 + 深度合并 + 命令行 `--set a.b.c=value` 覆盖,检测循环引用
- registry: 组件按名注册与构建,模型/数据集共用
- device: require_cuda() 守卫,按 CLAUDE.md 约定禁止在无 Nvidia GPU 的设备上训练;
  评估与导出走 resolve_device() 允许 CPU
- labels: multilabel / multiclass 两种图像级标签形式的共用定义
- logging / seed: 控制台+文件日志、随机种子与 cudnn 确定性

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Shaun Zhou
2026-09-02 17:54:55 +08:00
co-authored by Claude Opus 5
parent 0645fc19f7
commit f4eff8beee
7 changed files with 327 additions and 0 deletions
+33
View File
@@ -0,0 +1,33 @@
"""随机种子与 cudnn 确定性设置。"""
from __future__ import annotations
import os
import random
def seed_everything(seed: int, deterministic: bool = False) -> int:
random.seed(seed)
os.environ["PYTHONHASHSEED"] = str(seed)
try:
import numpy as np
np.random.seed(seed)
except ImportError: # pragma: no cover
pass
try:
import torch
torch.manual_seed(seed)
torch.cuda.manual_seed_all(seed)
if deterministic:
torch.backends.cudnn.deterministic = True
torch.backends.cudnn.benchmark = False
else:
torch.backends.cudnn.benchmark = True
except ImportError: # pragma: no cover
pass
return seed