Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions fastdeploy/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,24 @@ def __init__(
# set attribute from pretrained_config
for key, value in pretrained_config.items():
setattr(self, key, value)

# Check NUM_MAX_DISPATCH_TOKENS_PER_RANK environment variable
env_num_max_dispatch = envs.NUM_MAX_DISPATCH_TOKENS_PER_RANK
if env_num_max_dispatch is not None:
# Only check consistency if model config explicitly sets this value
if "num_max_dispatch_tokens_per_rank" in pretrained_config:
model_num_max_dispatch = pretrained_config["num_max_dispatch_tokens_per_rank"]
if model_num_max_dispatch != env_num_max_dispatch:
raise ValueError(
f"num_max_dispatch_tokens_per_rank mismatch: "
f"environment variable NUM_MAX_DISPATCH_TOKENS_PER_RANK={env_num_max_dispatch}, "
f"but model config has num_max_dispatch_tokens_per_rank={model_num_max_dispatch}. "
f"Please ensure they are consistent."
)
else:
# Use env value if model config doesn't explicitly set it
self.num_max_dispatch_tokens_per_rank = env_num_max_dispatch
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 建议 缺少单元测试覆盖新增逻辑。

建议在 tests/utils/test_config.py 中添加测试用例,验证以下场景:

  1. 环境变量未设置时使用默认值 128
  2. 环境变量设置时,与模型配置不一致时抛出 ValueError
  3. 环境变量设置时,模型配置未设置时使用环境变量值


# we need set default value when not exist
for key, value in PRETRAINED_INIT_CONFIGURATION.items():
if not hasattr(self, key):
Expand Down
7 changes: 7 additions & 0 deletions fastdeploy/envs.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,13 @@ def _validate_split_kv_size(value: int) -> int:
"FD_SAVE_OUTPUT_CACHE_FOR_PREEMPTED_REQUEST": lambda: bool(
int(os.getenv("FD_SAVE_OUTPUT_CACHE_FOR_PREEMPTED_REQUEST", "1"))
),
# Number of max dispatch tokens per rank for MoE computation.
# If set, it must match the value in model config if present, otherwise an error will be raised.
"NUM_MAX_DISPATCH_TOKENS_PER_RANK": lambda: (
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 建议 环境变量命名不符合项目规范。

项目中的环境变量统一使用 FD_ 前缀(如 FD_MOE_BACKENDFD_MOE_MXFP4_BACKEND),建议将此变量重命名为 FD_NUM_MAX_DISPATCH_TOKENS_PER_RANK

int(os.getenv("NUM_MAX_DISPATCH_TOKENS_PER_RANK", "0"))
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 建议 缺少对环境变量值的验证。

当环境变量设置为 0 或负数时可能导致问题。建议添加验证:

"NUM_MAX_DISPATCH_TOKENS_PER_RANK": lambda: (
    int(value) if (value := os.getenv("NUM_MAX_DISPATCH_TOKENS_PER_RANK")) and int(value) > 0
    else None
),

if os.getenv("NUM_MAX_DISPATCH_TOKENS_PER_RANK")
else None
),
}


Expand Down
Loading