| """ |
| 统一路径配置模块 - 兼容多环境 |
| |
| 支持的环境: |
| 1. AMLT 集群: /backup/... |
| 2. 本地开发 (home): ~/backup/... |
| 3. ZMS 集群: /mnt/data/zms/backup/... |
| |
| 使用方式: |
| from tools.path_config import PathConfig |
| |
| # 获取路径 |
| asset_library = PathConfig.get_asset_library_path() |
| voxel_cache = PathConfig.get_voxel_cache_path() |
| |
| # 或使用环境变量覆盖 |
| export PTH_ASSET_LIBRARY="/custom/path/asset_library" |
| """ |
|
|
| import os |
| from pathlib import Path |
|
|
|
|
| class PathConfig: |
| """统一路径配置类,自动检测环境并返回正确路径""" |
| |
| |
| _BACKUP_CANDIDATES = [ |
| "/backup", |
| "/mnt/data/zms/backup", |
| os.path.expanduser("~/backup"), |
| ] |
| |
| _backup_base = None |
| |
| @classmethod |
| def get_backup_base(cls) -> str: |
| """获取 backup 基础路径,自动检测环境""" |
| if cls._backup_base is not None: |
| return cls._backup_base |
| |
| |
| if os.environ.get("BACKUP_BASE"): |
| cls._backup_base = os.environ["BACKUP_BASE"] |
| return cls._backup_base |
| |
| |
| for candidate in cls._BACKUP_CANDIDATES: |
| check_path = os.path.join(candidate, "datas/InternScenes") |
| if os.path.exists(check_path): |
| cls._backup_base = candidate |
| print(f"[PathConfig] Detected backup base: {cls._backup_base}") |
| return cls._backup_base |
| |
| |
| cls._backup_base = os.path.expanduser("~/backup") |
| print(f"[PathConfig] Using default backup base: {cls._backup_base}") |
| return cls._backup_base |
| |
| @classmethod |
| def get_asset_library_path(cls) -> str: |
| """获取 asset_library 路径""" |
| env_path = os.environ.get("PTH_ASSET_LIBRARY") |
| if env_path and os.path.exists(env_path): |
| return env_path |
| return os.path.join(cls.get_backup_base(), "datas/InternScenes/asset_library") |
| |
| @classmethod |
| def get_asset_normalized_library_path(cls) -> str: |
| """获取 asset_library_normalized 路径""" |
| env_path = os.environ.get("PTH_ASSET_NORMALIZED_LIBRARY") |
| if env_path and os.path.exists(env_path): |
| return env_path |
| return os.path.join(cls.get_backup_base(), "datas/InternScenes/asset_library_normalized") |
| |
| @classmethod |
| def get_voxel_cache_path(cls) -> str: |
| """获取 voxel_cache 路径""" |
| env_path = os.environ.get("PTH_VOXEL_CACHE") |
| if env_path: |
| return env_path |
| return os.path.join(cls.get_backup_base(), "datas/InternScenes/voxel_cache") |
| |
| @classmethod |
| def get_sft_model_path(cls, checkpoint: str = "checkpoint-1100") -> str: |
| """获取 SFT 模型路径""" |
| env_path = os.environ.get("PTH_SFT_MODEL") |
| if env_path and os.path.exists(env_path): |
| return env_path |
| return os.path.join(cls.get_backup_base(), f"llm3d/sft_output/full_20251215_002635/{checkpoint}") |
| |
| @classmethod |
| def get_checkpoint_dir(cls, experiment_name: str) -> str: |
| """获取训练 checkpoint 目录""" |
| return os.path.join(cls.get_backup_base(), f"llm3d/grpo_checkpoints/{experiment_name}") |
| |
| @classmethod |
| def get_output_dir(cls, experiment_name: str) -> str: |
| """获取训练输出目录""" |
| return os.path.join(cls.get_backup_base(), f"llm3d/grpo/{experiment_name}") |
| |
| @classmethod |
| def get_unified_layout_path(cls) -> str: |
| """获取 unified-layout-aligned 路径""" |
| return os.path.join(cls.get_backup_base(), "datas/unified-layout-aligned") |
| |
| @classmethod |
| def get_layout_info_path(cls) -> str: |
| """获取 Layout_info 路径""" |
| return os.path.join(cls.get_backup_base(), "datas/InternScenes/Layout_info") |
| |
| @classmethod |
| def print_config(cls): |
| """打印当前路径配置""" |
| print("=" * 60) |
| print("PathConfig - Current Configuration") |
| print("=" * 60) |
| print(f"BACKUP_BASE: {cls.get_backup_base()}") |
| print(f"Asset Library: {cls.get_asset_library_path()}") |
| print(f"Asset Normalized: {cls.get_asset_normalized_library_path()}") |
| print(f"Voxel Cache: {cls.get_voxel_cache_path()}") |
| print(f"SFT Model: {cls.get_sft_model_path()}") |
| print("=" * 60) |
|
|
|
|
| |
| def get_backup_base() -> str: |
| return PathConfig.get_backup_base() |
|
|
| def get_asset_library_path() -> str: |
| return PathConfig.get_asset_library_path() |
|
|
| def get_asset_normalized_library_path() -> str: |
| return PathConfig.get_asset_normalized_library_path() |
|
|
| def get_voxel_cache_path() -> str: |
| return PathConfig.get_voxel_cache_path() |
|
|
|
|
| if __name__ == "__main__": |
| PathConfig.print_config() |
|
|