Adds ALL files needed for Dockerfile build:
- qwen3_6_scripts/ (baseline patches + our optimizations)
- vllm/ (full vllm package)
- paged_attention_v2_pytorch.py (V2 with single-bmm optimization)
- Dockerfile + computility-run.yaml
Our optimizations vs baseline:
1. paged_attn.py: pre-gathered context KV (eliminates 194 gather calls),
Triton try/fallback, V2 heuristic, threshold 32K→64K
2. paged_attention_v2_pytorch.py: fills NotImplementedError,
single-bmm Phase 1 (195 launches → 3)
3. patch_enable_triton.py: HAS_TRITON=True with safety fallback
4. patch_triton_tuning.py: BLOCK=64, NUM_WARPS=4 for BI-V100
5. computility-run.yaml: gpu-memory-utilization 0.9→0.95,
max-num-batched-tokens 8192→16384
This repo can now be submitted to dev.modelhub.org.cn as-is.
54 lines
2.2 KiB
Python
54 lines
2.2 KiB
Python
import os
|
|
|
|
from triton.runtime.cache import (FileCacheManager, default_cache_dir,
|
|
default_dump_dir, default_override_dir)
|
|
|
|
from vllm.logger import init_logger
|
|
|
|
logger = init_logger(__name__)
|
|
|
|
|
|
def maybe_set_triton_cache_manager() -> None:
|
|
"""Set environment variable to tell Triton to use a
|
|
custom cache manager"""
|
|
cache_manger = os.environ.get("TRITON_CACHE_MANAGER", None)
|
|
if cache_manger is None:
|
|
manager = "vllm.triton_utils.custom_cache_manager:CustomCacheManager"
|
|
logger.info("Setting Triton cache manager to: %s", manager)
|
|
os.environ["TRITON_CACHE_MANAGER"] = manager
|
|
|
|
|
|
class CustomCacheManager(FileCacheManager):
|
|
"""Re-implements Triton's cache manager, ensuring that a
|
|
unique cache directory is created for each process. This is
|
|
needed to avoid collisions when running with tp>1 and
|
|
using multi-processing as the distributed backend.
|
|
|
|
Note this issue was fixed by triton-lang/triton/pull/4295,
|
|
but the fix is not yet included in triton==v3.0.0. However,
|
|
it should be included in the subsequent version.
|
|
"""
|
|
|
|
def __init__(self, key, override=False, dump=False):
|
|
self.key = key
|
|
self.lock_path = None
|
|
if dump:
|
|
self.cache_dir = default_dump_dir()
|
|
self.cache_dir = os.path.join(self.cache_dir, self.key)
|
|
self.lock_path = os.path.join(self.cache_dir, "lock")
|
|
os.makedirs(self.cache_dir, exist_ok=True)
|
|
elif override:
|
|
self.cache_dir = default_override_dir()
|
|
self.cache_dir = os.path.join(self.cache_dir, self.key)
|
|
else:
|
|
# create cache directory if it doesn't exist
|
|
self.cache_dir = os.getenv("TRITON_CACHE_DIR",
|
|
"").strip() or default_cache_dir()
|
|
if self.cache_dir:
|
|
self.cache_dir = f"{self.cache_dir}_{os.getpid()}"
|
|
self.cache_dir = os.path.join(self.cache_dir, self.key)
|
|
self.lock_path = os.path.join(self.cache_dir, "lock")
|
|
os.makedirs(self.cache_dir, exist_ok=True)
|
|
else:
|
|
raise RuntimeError("Could not create or locate cache dir")
|