This document provides instructions for contributors to the vLLM Ascend project. Please read and follow these guidelines to ensure code quality, maintainability, and consistency.
Read linked documentation when it applies to the current task, using the relevant sections. Continue authorized local implementation and validation while preparing the evidence needed for PR review.
- Setup and Environment
- Testing
- Code Style
- NPU-Specific Considerations
- Model and Plugin Architecture
- Release Notes
- Commit Messages and Pull Requests
- Quick Start for Contributors
- References
Define environment variables in the centralized env_variables dictionary in vllm_ascend/envs.py.
Requirements:
- Add documentation for each environment variable in the
env_variablesdict comment - Specify default values and valid ranges
- Indicate whether the variable is sensitive (credentials, keys)
Never: Hardcode environment variable names throughout the codebase. Reference them from the central module using from vllm_ascend import envs.
Explain new environment variables in the PR for code review.
Reviewers must verify:
- The variable name follows the
VLLM_ASCEND_*naming convention - Default value is appropriate for all supported hardware
- Documentation is added to the
env_variablesdict - The variable is needed and existing configuration cannot cover the use case
Run tests appropriate to the change and complete required checks. Broaden or repeat testing when new changes, failures, or unresolved risks justify it.
When preparing or reviewing a PR, read the PR testing requirements for coverage, hardware evidence, and validation reporting. Use the other sections of the same guide for environment setup and test commands as needed.
-
Imports: All imports at the top of the file. Valid exceptions:
- Circular imports (use inline imports)
- Lazy loading for worker/isolation processes
- Type-checking imports wrapped in
if TYPE_CHECKING:
-
Global Variables: Avoid new global variables. Pass dependencies explicitly through function parameters.
Allowed:
- Constants named
ALL_UPPER_CASE - Immutable configuration objects
If mutable module-level state is necessary, explain its lifetime and concurrency implications in the PR.
- Constants named
-
No Magic Numbers: Use named constants with descriptive names.
-
Descriptive Naming: Use names that describe functionality, not implementation details.
- Classes:
PascalCase(e.g.,NPUModelRunner,AscendSampler,ACLGraphManager) - Functions/Methods:
snake_case(e.g.,forward_pass,compute_attention) - Constants:
ALL_UPPER_CASE - Variables:
snake_case(e.g.,token_ids,sequence_lengths)
Warning: tensor.item() operations cause synchronization overhead on NPU when the tensor is on device.
If the tensor is a device tensor, calling item() triggers a synchronous data transfer from NPU to CPU. This can severely degrade performance in hot paths, causing AsyncScheduler to block here.
Review Requirements:
- Profile synchronization introduced in hot paths before merging
- Consider alternative patterns:
- Keep values on device when possible
- Batch operations to reduce sync frequency
- Use device-side operations (e.g.,
torch.argmax,torch.sum)
- Document when
item()is unavoidable (e.g., logging, conditional logic)
Additional NPU-specific best practices:
- Avoid CPU-NPU memory transfers in hot paths
- Prefer in-place operations where safe (e.g.,
x.add_(),x.mul_()) - Monitor memory fragmentation, especially for long-running processes
- Test with realistic workloads on actual NPU hardware (Ascend 910B/C)
vLLM Ascend is a hardware plugin that integrates with upstream vLLM via the pluggable hardware interface. Prefer existing upstream implementations and extension points. Ascend-specific model adaptations are also registered in the model registry; follow existing registration and inheritance patterns when working on these models.
Choose the integration approach that fits the change:
-
Patching (in
vllm_ascend/patch/):vllm_ascend/patch/platform/- Platform-level patches (distributed, scheduling)vllm_ascend/patch/worker/- Worker-level patches (model-specific behavior)- Patch is not the best solution for all cases. Use it when necessary.
-
Inheritance:
NPUModelRunner(GPUModelRunner)- Extend vLLM model runner with NPU-specific behaviorAscendSampler- Extend vLLM sampler with NPU-specific operations- Add NPU-specific components via composition (e.g.,
AclGraphManager) - Custom Operators - NPU-specific custom operators (e.g.,
AscendRMSNorm)
-
External upstream contributions where appropriate
Explain new patches in the PR for architectural review.
When adding or changing a patch, read the patch strategy for lifecycle, registration, and removal-plan requirements.
Reviewers must verify:
- The patch targets the correct upstream component
- The patch is minimal and focused
- Performance implications are understood
- A long-term plan exists for upstream contribution
Explain new model_runner behavior in the PR for architectural review.
Reviewers must verify:
- Why existing extension points cannot cover the new behavior
- Performance implications on NPU hardware
- Compatibility with existing model implementations
- Long-term maintainability and test coverage
NPU Model Runner Files:
vllm_ascend/worker/v1/model_runner.py- vLLM v1 model runner (isolated V1 zone, removal-tracked)vllm_ascend/worker/v2/model_runner.py- vLLM v2 model runnervllm_ascend/worker/v1/_310p/model_runner_310p.py- Ascend 310P model runner (isolated V1 zone, removal-tracked)
Every PR with a user-facing change must ship a release note fragment in the same PR.
Required for: new models, hardware, or operators; new features; changes to user-facing APIs, parameters, environment variables, or configuration; breaking changes, deprecations, and default behavior changes; dependency and toolchain updates (CANN, torch_npu, triton-ascend, vLLM alignment); measurable performance improvements; and important bug fixes.
Not required for: internal refactors, tests, CI, build scripts, tooling, and documentation edits.
Add release_notes/fragments/<PR number>.yaml following release_notes/TEMPLATE.yaml. See
release_notes/README.md for the principles and the field rules. When in doubt, add a
fragment: the release manager drops extra entries at release time. Reviewers confirm the
fragment together with the code; there is no CI gate.
Follow the Conventional Commits format and must include a sign-off:
git commit -s -m "<type>: <summary>" -m "<body - explaining what changed and why>"Valid Types: feat, fix, perf, refactor, test, docs, chore
Use a PR title accepted by the CI check linked in the PR submission checklist.
When creating a PR, please follow the template in .github/PULL_REQUEST_TEMPLATE.md and ensure the following sections are completed:
Note: The PR description will be automatically updated by GitHub Actions to include vLLM version info at the bottom. If you update the PR description via API or CLI, make sure to preserve the
- vLLM version:and- vLLM main:lines.
- What this PR does / why we need it? - Clearly describe the changes and their purpose
- Does this PR introduce any user-facing change? - Indicate if there are any user-visible changes
- How was this patch tested? - Describe how you tested the changes. Examples:
- Unit tests added/updated: list the test files
- Manual testing: provide the test steps and commands
- CI testing: indicate if only CI verification is needed
Document public APIs and reflect user-facing behavior changes in the project docs.
For environment setup, use the contribution guide as needed.
Before pushing, run the required checks for all file types, including Markdown:
bash format.sh ciInspect any formatter changes and include them in the commit. Push to your fork and create the PR against the upstream repository, following the commit and PR requirements above.