Skip to content

test#90

Open
AlexanderDokuchaev wants to merge 1 commit into
developfrom
test_123
Open

test#90
AlexanderDokuchaev wants to merge 1 commit into
developfrom
test_123

Conversation

@AlexanderDokuchaev
Copy link
Copy Markdown
Owner

Changes

Reason for changes

Related tickets

Tests

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a new wrap_tensor utility function to the tensor module with minimal context provided in the PR description (title is simply "test" with an empty template).

Changes:

  • Added wrap_tensor function to src/nncf/tensor/tensor.py that wraps input data into a Tensor object, returning existing Tensor instances unchanged or creating new ones with deep-copied data

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/nncf/tensor/tensor.py
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.
Copy link

Copilot AI Feb 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The documentation style uses NumPy format (Parameters/Returns sections with dashes), while the rest of the file uses reStructuredText format with :param and :return tags (see lines 243-252, 276-281, 288-293, 299-302). The documentation should be consistent with the existing convention in this file.

Suggested change
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 uses AI. Check for mistakes.
Comment thread src/nncf/tensor/tensor.py
Comment on lines +317 to +337
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.
"""
import copy

if isinstance(data, Tensor):
return data
return Tensor(copy.deepcopy(data))
Copy link

Copilot AI Feb 16, 2026

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 uses AI. Check for mistakes.
Comment thread src/nncf/tensor/tensor.py
If input is already a Tensor, returns it unchanged. Otherwise, returns
a new Tensor instance created from the input data.
"""
import copy
Copy link

Copilot AI Feb 16, 2026

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 uses AI. Check for mistakes.
Comment thread src/nncf/tensor/tensor.py
Comment on lines +317 to +323
def wrap_tensor(data: Tensor) -> Tensor:
"""
Wrap input data into a Tensor object.

Parameters
----------
data : Tensor
Copy link

Copilot AI Feb 16, 2026

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: Tensor but the documentation states it can be "either a Tensor instance or data that can be used to construct a Tensor". The type hint should be data: Union[Tensor, TTensor] or data: Any to match the intended behavior described in the docstring.

Suggested change
def wrap_tensor(data: Tensor) -> Tensor:
"""
Wrap input data into a Tensor object.
Parameters
----------
data : Tensor
def wrap_tensor(data: Union[Tensor, TTensor]) -> Tensor:
"""
Wrap input data into a Tensor object.
Parameters
----------
data : Union[Tensor, TTensor]

Copilot uses AI. Check for mistakes.
Comment thread src/nncf/tensor/tensor.py
Comment on lines +333 to +337
import copy

if isinstance(data, Tensor):
return data
return Tensor(copy.deepcopy(data))
Copy link

Copilot AI Feb 16, 2026

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.

Suggested change
import copy
if isinstance(data, Tensor):
return data
return Tensor(copy.deepcopy(data))
if isinstance(data, Tensor):
return data
return Tensor(data)

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants