Add Python config API for NPU backend settings#47
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a process-global Python configuration API for the AMD Triton NPU backend, enabling programmatic control of backend settings that were previously only configurable via environment variables, while keeping env vars as backward-compatible fallbacks.
Changes:
- Introduces
amd_triton_npu/backend/config.pyexposing a singletonnpu_config, plusset_config()andconfig_context()for overrides. - Replaces direct
os.getenv(...)reads in the driver/compiler withnpu_configproperties and removes duplicated air project path helper logic. - Adds
amd_triton_npu/backend/__init__.pyto support package/module structure.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 6 comments.
| File | Description |
|---|---|
amd_triton_npu/backend/config.py |
New config singleton + helpers with env-var fallbacks |
amd_triton_npu/backend/driver.py |
Swaps env var reads for config access; removes duplicated path helper |
amd_triton_npu/backend/compiler.py |
Uses config for air project path dumping; removes duplicated helper |
amd_triton_npu/backend/__init__.py |
Adds package marker for backend module |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
I think we should also add #44 |
9de8e09 to
ca7c539
Compare
Introduces a centralized config module (config.py) with a singleton npu_config object that provides programmatic control over the 5 settings previously only available via environment variables. Env vars are preserved as fallback defaults for backward compatibility. Closes #43 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Treat None as "unset" in air_project_path setter (reverts to env var / default instead of crashing with Path(None)) - Use __dict__.copy() in config_context() so new fields are automatically saved/restored - Mention both config property and env var in error messages for output_format and transform_tiling_script - Incorporate PR #44 logging changes (rebase on top of feature/logging-knob-issue-40) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Points to erwei-xilinx/triton-shared@c043a85 which adds TPtrIR to TritonShared plugin LINK_LIBS, fixing the flaky parallel build failure (facebookincubator/triton-shared#19). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
amd_triton_npu/backend/config.pywith a singletonnpu_configobject that provides programmatic control over 5 settings previously only available via environment variablesos.getenvcalls indriver.pyandcompiler.pywith reads from the config singleton_get_air_project_path()function that existed in both filesAPI
All existing environment variables continue to work as fallback defaults — fully backward compatible.
compile_onlyAMD_TRITON_NPU_COMPILE_ONLYFalsetransform_tiling_scriptAIR_TRANSFORM_TILING_SCRIPTNonebf16_emulationAMD_TRITON_NPU_BF16_EMULATIONFalseoutput_formatAMD_TRITON_NPU_OUTPUT_FORMATNone(auto-detect)air_project_pathAMD_TRITON_NPU_AIR_PROJECT_PATH./air_projectCloses #43
Test plan
python -c "from triton.backends.amd_triton_npu.config import npu_config, set_config, config_context"AMD_TRITON_NPU_COMPILE_ONLY=1 python -c "from triton.backends.amd_triton_npu.config import npu_config; assert npu_config.compile_only"AMD_TRITON_NPU_BF16_EMULATION=1 python -c "from triton.backends.amd_triton_npu.config import npu_config; npu_config.bf16_emulation = False; assert not npu_config.bf16_emulation"🤖 Generated with Claude Code