Files
project_6/qwen3_6_scripts/patch_worker_profile_override.py
project6-dev 8030a11b96 feat: 替换为 project_7 验证通过的 wudixzy stack
project_7 docker build 已在竞赛平台验证成功。
完整搬运 wudixzy/competition stack:
- qwen3_5.py 2615 行 (12 个 corex .so 调用)
- patch_ops.sh 251 行 (set -eo pipefail + cd dirname)
- 12 prebuilt corex .so (SHA256 verified)
- 13 CUDA .cu 源码 + 11 build scripts
- 9 vendor overrides (block/sampler/scheduler)
- transformers-4.55.3 offline wheel
- computility-run.yaml: 262144 max-model-len, BI100 env vars
- Dockerfile 结构不变 (COPY qwen3_6_scripts + RUN patch_ops.sh)
2026-08-12 03:31:05 +00:00

82 lines
3.4 KiB
Python

from patch_utils import package_root, replace_one_of
WORKER = package_root("vllm") / "worker" / "worker.py"
CLEAN_BLOCK = """\
# Profile the memory usage of the model and get the maximum number of
# cache blocks that can be allocated with the remaining free memory.
torch.cuda.empty_cache()
# Execute a forward pass with dummy inputs to profile the memory usage
# of the model.
self.model_runner.profile_run()
"""
GUARDED_BLOCK = """\
# Profile the memory usage of the model and get the maximum number of
# cache blocks that can be allocated with the remaining free memory.
torch.cuda.empty_cache()
# Execute a forward pass with dummy inputs to profile the memory usage
# of the model. Mark this synthetic pass so BI100_PROFILE can skip
# timing it by default; profiling real requests is the useful signal.
_bi100_prev_startup_profile = os.environ.get("BI100_IN_STARTUP_PROFILE")
os.environ["BI100_IN_STARTUP_PROFILE"] = "1"
try:
self.model_runner.profile_run()
finally:
if _bi100_prev_startup_profile is None:
os.environ.pop("BI100_IN_STARTUP_PROFILE", None)
else:
os.environ["BI100_IN_STARTUP_PROFILE"] = _bi100_prev_startup_profile
"""
NEW_BLOCK = """\
# Profile the memory usage of the model and get the maximum number of
# cache blocks that can be allocated with the remaining free memory.
torch.cuda.empty_cache()
# BI100: Qwen3.6 batched dummy profile_run can trip GDN non-finite
# checks before the server starts. If the operator explicitly provides
# --num-gpu-blocks-override, trust that conservative capacity value and
# skip only the synthetic profile pass. Real inference still uses the
# normal GDN fail-fast path.
if self.cache_config.num_gpu_blocks_override is not None:
cache_block_size = self.get_cache_block_size_bytes()
if cache_block_size == 0:
num_cpu_blocks = 0
else:
num_cpu_blocks = int(self.cache_config.swap_space_bytes //
cache_block_size)
logger.warning(
"[BI100] skipping worker.profile_run because "
"num_gpu_blocks_override=%d was explicitly set",
self.cache_config.num_gpu_blocks_override)
gc.collect()
torch.cuda.empty_cache()
return self.cache_config.num_gpu_blocks_override, max(num_cpu_blocks, 0)
# Execute a forward pass with dummy inputs to profile the memory usage
# of the model. Mark this synthetic pass so BI100_PROFILE can skip
# timing it by default; profiling real requests is the useful signal.
_bi100_prev_startup_profile = os.environ.get("BI100_IN_STARTUP_PROFILE")
os.environ["BI100_IN_STARTUP_PROFILE"] = "1"
try:
self.model_runner.profile_run()
finally:
if _bi100_prev_startup_profile is None:
os.environ.pop("BI100_IN_STARTUP_PROFILE", None)
else:
os.environ["BI100_IN_STARTUP_PROFILE"] = _bi100_prev_startup_profile
"""
replace_one_of(
WORKER,
[
(GUARDED_BLOCK, NEW_BLOCK),
(CLEAN_BLOCK, NEW_BLOCK),
],
required=True,
already_contains="[BI100] skipping worker.profile_run",
)