Skip to content

test2#91

Open
AlexanderDokuchaev wants to merge 1 commit into
ad/copilot_instructionfrom
test_123
Open

test2#91
AlexanderDokuchaev wants to merge 1 commit into
ad/copilot_instructionfrom
test_123

Conversation

@AlexanderDokuchaev
Copy link
Copy Markdown
Owner

@AlexanderDokuchaev AlexanderDokuchaev commented Feb 16, 2026

Changes

Reason for changes

Related tickets

Tests

Test examples - cancelled

Weight compression - cancelled

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 utility function wrap_tensor to the src/nncf/tensor/tensor.py module. The function is designed to wrap input data into a Tensor object, returning the input unchanged if it's already a Tensor, or creating a new Tensor instance from the input data using copy.deepcopy.

Changes:

  • Added wrap_tensor function to provide a utility for wrapping data into Tensor objects

Comment thread src/nncf/tensor/tensor.py
Comment on lines +318 to +332
"""
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.
"""
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 docstring format doesn't match the codebase convention. This file uses the :param and :return: format (see lines 246-247, 279-280, 291-292, 301-302), not NumPy-style docstrings with Parameters/Returns sections. Please update to match the existing format used throughout this file and the nncf.tensor module.

Copilot generated this review using guidance from repository custom instructions.
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 data: Tensor is incorrect. According to the function's logic and documentation, the parameter can accept both Tensor instances and other data types that can be wrapped into a Tensor. The type hint should be data: Any (similar to unwrap_tensor_data on line 287) or data: Union[Tensor, TTensor] to accurately reflect what the function accepts.

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
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 module level (at the top of the file with other imports) rather than inside the function. This is a standard Python convention and matches the codebase style. Other files in the repository import copy at the module level (e.g., src/nncf/common/graph/patterns/patterns.py line 11, src/nncf/common/utils/caching.py line 11).

Copilot generated this review using guidance from repository custom instructions.
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.

The use of copy.deepcopy(data) is unnecessary and could be a performance bottleneck. Looking at the Tensor.init implementation (line 34), it already handles unwrapping if the input is a Tensor instance. Simply calling Tensor(data) without deepcopy should be sufficient and more efficient. The deepcopy operation can be expensive for large tensors and is typically not needed here.

Suggested change
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))
def wrap_tensor(data: Any) -> Tensor:
"""
Wrap input data into a Tensor object.
: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.
"""
if isinstance(data, Tensor):
return data
return Tensor(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.

The new wrap_tensor function lacks test coverage. The repository uses comprehensive pytest-based testing, as seen in tests/common/tensor/test_disaptcher.py which tests similar utility functions like _unwrap_tensors. Please add tests for wrap_tensor to verify its behavior with different input types (e.g., Tensor instances, numpy arrays, torch tensors).

Copilot uses AI. Check for mistakes.
@AlexanderDokuchaev AlexanderDokuchaev force-pushed the ad/copilot_instruction branch 2 times, most recently from c4ad30a to 0e153b4 Compare February 16, 2026 20:21
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