-
Notifications
You must be signed in to change notification settings - Fork 9
Fix alias output naming and improve Spike I/O diagnostics #51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
hgt312
wants to merge
1
commit into
aws-neuron:main
Choose a base branch
from
hgt312:alias-output-naming-fix
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -195,8 +195,49 @@ def _check_dtype_compatibility( | |
| f"got {actual_dtype}" | ||
| ) | ||
|
|
||
| _ALIAS_SUFFIX = ".must_alias_input" | ||
|
|
||
| def _resolve_alias_inputs(self, inputs): | ||
| """Auto-remap aliased input names so callers can use original param names. | ||
|
|
||
| NKIPy's tracer renames mutated (aliased) parameters from ``"X"`` to | ||
| ``"X.must_alias_input"`` in the compiled NEFF. This method lets | ||
| callers pass the natural name ``"X"`` and transparently appends the | ||
| suffix when the NEFF expects it. Inputs that already carry the | ||
| suffix or are not aliased are passed through unchanged. | ||
| """ | ||
| resolved = {} | ||
| for k, v in inputs.items(): | ||
| if k not in self.input_tensors_info: | ||
| alias_key = k + self._ALIAS_SUFFIX | ||
| if alias_key in self.input_tensors_info: | ||
| resolved[alias_key] = v | ||
| continue | ||
| resolved[k] = v | ||
| return resolved | ||
|
|
||
| def _validate_io(self, inputs, outputs): | ||
| """Validate that caller-supplied I/O dicts match the compiled NEFF. | ||
|
|
||
| Checks tensor names, shapes, dtypes, and core placement. Raises | ||
| ``ValueError`` with the expected NEFF names on any name mismatch, | ||
| so callers get actionable diagnostics instead of a bare ``KeyError``. | ||
| """ | ||
| model_core_id = self.model_ref.core_id | ||
|
|
||
| unknown_inputs = set(inputs) - set(self.input_tensors_info) | ||
| if unknown_inputs: | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like the checks! |
||
| raise ValueError( | ||
| f"Unknown input(s) {unknown_inputs} for model '{self.name}'. " | ||
| f"Expected inputs: {list(self.input_tensors_info.keys())}" | ||
| ) | ||
| unknown_outputs = set(outputs) - set(self.output_tensors_info) | ||
| if unknown_outputs: | ||
| raise ValueError( | ||
| f"Unknown output(s) {unknown_outputs} for model '{self.name}'. " | ||
| f"Expected outputs: {list(self.output_tensors_info.keys())}" | ||
| ) | ||
|
|
||
| for k, v in inputs.items(): | ||
| tensor_core_id = v.tensor_ref.core_id | ||
| assert tensor_core_id == model_core_id, ( | ||
|
|
@@ -246,6 +287,11 @@ def __call__( | |
| outputs = {tensor.name: tensor for tensor in output_tensors} | ||
| auto_allocated = True | ||
|
|
||
| # Auto-resolve alias input naming: if caller passes "X" but the NEFF | ||
| # expects "X.must_alias_input", remap transparently so callers don't | ||
| # need to know about the alias suffix convention. | ||
| inputs = self._resolve_alias_inputs(inputs) | ||
|
|
||
| self._validate_io(inputs, outputs) | ||
|
|
||
| input_refs = {k: v.tensor_ref for k, v in inputs.items()} | ||
|
|
||
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
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't want to complicate the handling of alias naming in spike.
Spike is a wrapper on runtime, it should not need to know how we lower the function into NEFFs. It should only deal with what's available in the NEFFs.
This specific problem can be addressed at the user level? The caller can pass
.must_alias_inputin the input tensor list.A proper solution can be in the NEFF lowering in NKIPy (but we want to make sure we are aligned with NKI)