-
Notifications
You must be signed in to change notification settings - Fork 0
test #90
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
base: develop
Are you sure you want to change the base?
test #90
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -312,3 +312,26 @@ def get_tensor_backend(backend: BackendType) -> TensorBackend: | |||||||||||||||||||||||||||||||
| raise nncf.ValidationError(msg) | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| return BACKEND_TO_TENSOR_BACKEND[backend] | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| def wrap_tensor(data: Tensor) -> Tensor: | ||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||
| Wrap input data into a Tensor object. | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| Parameters | ||||||||||||||||||||||||||||||||
| ---------- | ||||||||||||||||||||||||||||||||
| data : Tensor | ||||||||||||||||||||||||||||||||
| Input data to be wrapped. Can be either a Tensor instance or data that | ||||||||||||||||||||||||||||||||
| can be used to construct a Tensor. | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| Returns | ||||||||||||||||||||||||||||||||
| ------- | ||||||||||||||||||||||||||||||||
| Tensor | ||||||||||||||||||||||||||||||||
| If input is already a Tensor, returns it unchanged. Otherwise, returns | ||||||||||||||||||||||||||||||||
| a new Tensor instance created from the input data. | ||||||||||||||||||||||||||||||||
|
Comment on lines
+321
to
+331
|
||||||||||||||||||||||||||||||||
| Parameters | |
| ---------- | |
| data : Tensor | |
| Input data to be wrapped. Can be either a Tensor instance or data that | |
| can be used to construct a Tensor. | |
| Returns | |
| ------- | |
| Tensor | |
| If input is already a Tensor, returns it unchanged. Otherwise, returns | |
| a new Tensor instance created from the input data. | |
| :param data: Input data to be wrapped. Can be either a Tensor instance or | |
| data that can be used to construct a Tensor. | |
| :return: If input is already a Tensor, returns it unchanged. Otherwise, | |
| returns a new Tensor instance created from the input data. |
Copilot
AI
Feb 16, 2026
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.
The import statement should be placed at the top of the file with other imports, not inside the function. The codebase follows the convention of placing all imports at module level (lines 11-23).
Copilot
AI
Feb 16, 2026
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.
This function appears to be redundant. The Tensor class constructor (line 34) already handles both Tensor instances and raw data, extracting the .data attribute when a Tensor is passed. Simply calling Tensor(data) would achieve the same result without needing a separate wrapper function. If this function is intended to perform a deep copy, that intent should be documented and the implementation should be reconsidered given the issues with deepcopy on tensor backends.
Copilot
AI
Feb 16, 2026
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.
The use of copy.deepcopy is unnecessary and potentially problematic. The Tensor.__init__ method (line 34) already handles both Tensor instances and raw data correctly by extracting .data from Tensor objects. Additionally, deepcopy can be expensive for large tensors and may not work correctly with all tensor backends (e.g., CUDA tensors). Consider simply using return Tensor(data) for non-Tensor inputs.
| import copy | |
| if isinstance(data, Tensor): | |
| return data | |
| return Tensor(copy.deepcopy(data)) | |
| if isinstance(data, Tensor): | |
| return data | |
| return Tensor(data) |
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.
The type hint specifies
data: Tensorbut the documentation states it can be "either a Tensor instance or data that can be used to construct a Tensor". The type hint should bedata: Union[Tensor, TTensor]ordata: Anyto match the intended behavior described in the docstring.