Skip to content
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

[BugFix] Fixed Inappropriate Logical Expression #16272

Merged
merged 1 commit into from Dec 26, 2023

Conversation

fazledyn-or
Copy link
Contributor

Summary

This PR fixes a logical bug in your code.

Description

While triaging your project, our bug fixing tool generated the following message(s)-

In file: pytorch.py, method: tensor_split, a logical equality check operation was performed. The operands are such that the comparison operation always returns either true or false. Such logical short circuits in code lead to unintended behavior. iCR suggested that the logical operation should be reviewed for correctness.

Solution / Suggested Changes

In the tensor_split method, there's a comparsion that checks if the input tensor is zero-dimensional or one-dimensional long tensor. In the comparsion, there's a typo that converts the shape of the tensor to a list and compares against integer.

Example

Running an example code like below gives us the following result-

import torch

# Create a one-dimensional tensor
tensor_0d = torch.tensor(43)
tensor_1d = torch.tensor([1, 2, 3, 4, 5])

# Print the tensor and its shape
print(tensor_0d)
print(tensor_1d)

print("Tensor Shape:", tensor_0d.shape)
print("Tensor Shape:", tensor_1d.shape)

print("Tensor Shape List:", list(tensor_0d.shape))
print("Tensor Shape List:", list(tensor_1d.shape))

print("Tensor Len:", len(tensor_0d.shape))
print("Tensor Len:", len(tensor_1d.shape))
tensor(43)
tensor([1, 2, 3, 4, 5])
Tensor Shape: torch.Size([])
Tensor Shape: torch.Size([5])
Tensor Shape List: []
Tensor Shape List: [5]
Tensor Len: 0
Tensor Len: 1

CLA Requirements

This section is only relevant if your project requires contributors to sign a Contributor License Agreement (CLA) for external contributions.

All contributed commits are already automatically signed off.

The meaning of a signoff depends on the project, but it typically certifies that committer has the rights to submit this work under the same license and agrees to a Developer Certificate of Origin (see https://developercertificate.org/ for more information).

- Git Commit SignOff documentation

Sponsorship and Support

This work is done by the security researchers from OpenRefactory and is supported by the Open Source Security Foundation (OpenSSF): Project Alpha-Omega. Alpha-Omega is a project partnering with open source software project maintainers to systematically find new, as-yet-undiscovered vulnerabilities in open source code - and get them fixed – to improve global software supply chain security.

The bug is found by running the Intelligent Code Repair (iCR) tool by OpenRefactory and then manually triaging the results.

Copy link
Contributor

@quic-sanirudh quic-sanirudh left a comment

Choose a reason for hiding this comment

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

LGTM, Thanks. Looks like there is a lint error, once that is fixed we can merge this.

In the `tensor_split` method, there's a comparsion
that checks if the input tensor is zero-dimensional
or one-dimensional long tensor.

In the comparsion, there's a typo that converts
the shape of the tensor to a list and compares
against integer.

This commit fixes the bug by comapring the
length of the tensor against the integer.

Signed-off-by: fazledyn-or <ataf@openrefactory.com>
@quic-sanirudh
Copy link
Contributor

@tvm-bot rerun

@junrushao junrushao merged commit 1c45389 into apache:main Dec 26, 2023
17 checks passed
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.

None yet

3 participants