Add target to npu_config (fixes #54)#56
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a programmatic way to set the NPU “target” (npu1/npu2) via _NPUConfig, and wires NPU version detection to use that config (with env var fallback) to support cross-compilation flows.
Changes:
- Introduces
npu_config.targetwith validation + env var fallback (AMD_TRITON_NPU_TARGET). - Updates
detect_npu_version()to readnpu_config.targetinstead ofos.getenv(). - Updates config module usage examples to include
targetwithset_config()/config_context().
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
amd_triton_npu/backend/driver.py |
Switches NPU target selection in detect_npu_version() to use npu_config.target and updates related messaging/docs. |
amd_triton_npu/backend/config.py |
Adds target to _NPUConfig, including validation, reset behavior, and inclusion in set_config()/config_context(). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
25ff223 to
9343ed8
Compare
AMD_TRITON_NPU_TARGET was only readable via os.getenv() in detect_npu_version(), bypassing the _NPUConfig pattern used by all other settings. Add a `target` property to _NPUConfig so users can set it via npu_config.target, set_config(), or config_context(). Closes #54 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Address PR review feedback: - target getter now raises ValueError when AMD_TRITON_NPU_TARGET is set to an unsupported value instead of silently falling back to None - detect_npu_version() error message mentions both npu_config.target and the env var name for easier diagnosis 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
targetproperty to_NPUConfigsoAMD_TRITON_NPU_TARGETcan be set programmatically vianpu_config.target,set_config(), orconfig_context()— matching the pattern used by all other backend settings.detect_npu_version()to read fromnpu_config.targetinstead of directly fromos.getenv().AMD_TRITON_NPU_TARGETenv var continues to work as a fallback.Closes #54
Test plan
npu_config.targetreturnsNoneby default (no env var, no programmatic set)npu_config.target = "npu2"works;npu_config.target = "invalid"raisesValueErrornpu_config.target = "NPU1"normalizes to"npu1"set_config(target="npu1")andconfig_context(target="npu2")work correctlynpu_config.reset()clears programmatic targetAMD_TRITON_NPU_TARGET=npu2env var still works as fallbackdetect_npu_version()returns the configured target without querying hardware🤖 Generated with Claude Code