-
Notifications
You must be signed in to change notification settings - Fork 18
#343: Support collections of tensors in args/kwargs for compile #701
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
akhilg-nv
wants to merge
5
commits into
main
Choose a base branch
from
dev-akhilg-230-collections-compile
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 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
48b5d7d
#230: Support collections of tensors in args/kwargs for compile
akhilg-nv 87ecff6
improve tests, review fixes
akhilg-nv e924c8b
Cache inputinfo structure at compile time, improve test coverage
akhilg-nv 923cec5
Update serialization and deserialization
akhilg-nv 4831cf1
fix missing tensor in stack info for shape mismatch
akhilg-nv 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -195,20 +195,61 @@ def add(a, b): | |
| ], | ||
| ) | ||
|
|
||
| # Recursively extract inputs from containers to get individual tensors for validation and execution | ||
| def extract_inputs(tensors, input_info_names): | ||
| def extract_recursive(tensor, name_prefix): | ||
| if isinstance(tensor, dict): | ||
| result = [] | ||
| for key in sorted(tensor.keys()): | ||
| nested_name = f"{name_prefix}.{key}" | ||
| if nested_name in input_info_names: | ||
| result.append(tensor[key]) | ||
| else: | ||
| result.extend(extract_recursive(tensor[key], nested_name)) | ||
| return result | ||
| elif isinstance(tensor, (list, tuple)): | ||
| result = [] | ||
| for idx, value in enumerate(tensor): | ||
| nested_name = f"{name_prefix}[{idx}]" | ||
| if nested_name in input_info_names: | ||
| result.append(value) | ||
| else: | ||
| result.extend(extract_recursive(value, nested_name)) | ||
| return result | ||
| else: # Regular tensor | ||
| if name_prefix in input_info_names: | ||
| return [tensor] | ||
akhilg-nv marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| else: | ||
| return [] | ||
|
||
|
|
||
| flattened = [] | ||
| for name_idx, tensor in enumerate(tensors): | ||
| arg_name = self._arg_names[name_idx] | ||
| flattened.extend(extract_recursive(tensor, arg_name)) | ||
| return flattened | ||
|
|
||
| flattened_tensors = extract_inputs(input_tensors, set(self.input_infos.keys())) | ||
| expected_devices = ["gpu" if isinstance(info, InputInfo) else "cpu" for info in self.input_infos.values()] | ||
| for tensor, expected_device, arg_name in zip(input_tensors, expected_devices, self._arg_names): | ||
|
|
||
| # Validate flattened tensors against input_infos | ||
| if len(flattened_tensors) != len(expected_devices): | ||
| raise_error( | ||
| f"Mismatch between number of flattened tensors ({len(flattened_tensors)}) and expected inputs ({len(expected_devices)})." | ||
| ) | ||
|
|
||
| for tensor, expected_device, info_name in zip(flattened_tensors, expected_devices, self.input_infos.keys()): | ||
| producer = tensor.trace_tensor.producer | ||
| if not isinstance(producer, Constant): | ||
| raise_error(f"Tensor `{arg_name}` is not evaluated.", ["Hint: Try calling `.eval()` on the tensor."]) | ||
| raise_error(f"Tensor `{info_name}` is not evaluated.", ["Hint: Try calling `.eval()` on the tensor."]) | ||
| if tensor.device.kind != expected_device: | ||
| raise_error( | ||
| "Unexpected tensor device.", | ||
| [ | ||
| f"For tensor: `{arg_name}`, expected to be on device: {expected_device} but got: {tensor.device.kind}.\n", | ||
| f"For tensor: `{info_name}`, expected to be on device: {expected_device} but got: {tensor.device.kind}.\n", | ||
| ], | ||
| ) | ||
|
|
||
| input_memrefs = [inp.trace_tensor.producer.data for inp in input_tensors] | ||
| input_memrefs = [inp.trace_tensor.producer.data for inp in flattened_tensors] | ||
| try: | ||
| output_memrefs = self._session.execute_function( | ||
| "main", in_args=input_memrefs, stream=self.stream._active_cuda_stream, client=self._runtime_client | ||
|
|
||
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.
Uh oh!
There was an error while loading. Please reload this page.