Skip to content

Conversation

Silv3S
Copy link
Contributor

@Silv3S Silv3S commented Sep 15, 2025

  • remove unused variables,
  • add compiler flag to prevent this in the future

@Copilot Copilot AI review requested due to automatic review settings September 15, 2025 09:22
Copy link
Contributor

@Copilot 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 removes unused variables from the codebase and adds a compiler flag to detect unused variables in the future. The changes focus on cleaning up variables that were declared but never referenced in the code.

  • Removes unused output_size variable from RoiAlign kernel
  • Removes unused dg_data and db_data variables from LayerNorm backward kernel
  • Adds -Werror=unused-variable compiler flag to catch future unused variables

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
src/ATen/native/xpu/sycl/RoiAlignKernels.cpp Removes unused output_size variable calculation
src/ATen/native/xpu/sycl/LayerNormKernels.cpp Removes unused pointer variables dg_data and db_data
CMakeLists.txt Adds compiler flag to treat unused variables as errors

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

CMakeLists.txt Outdated
@@ -25,6 +25,7 @@ set(PROJECT_VERSION "2.3.0")
# Avoid SYCL compiler error
if(NOT WIN32)
string(APPEND CMAKE_CXX_FLAGS " -Wno-error")
string(APPEND CMAKE_CXX_FLAGS " -Werror=unused-variable")
Copy link
Contributor

Choose a reason for hiding this comment

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

Enabling this option is good for the final code quality, but it also requires every compilation in development to follow this rule. Such checks would be better placed in CI.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, I've passed this flag as env variable in linux_build CI pipeline

@@ -94,6 +94,7 @@ jobs:
- name: Build Pytorch on ${{ needs.runner.outputs.hostname }}
run: |
export USE_XCCL=1
export CXXFLAGS="${CXXFLAGS} -Werror=unused-variable"
Copy link
Contributor

Choose a reason for hiding this comment

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

Exporting this flag would propagate it to the entire PyTorch build, which may cause build failures in third-party components.

Copy link
Contributor Author

@Silv3S Silv3S Sep 19, 2025

Choose a reason for hiding this comment

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

I'd opt for keeping this in CMake, because even if it affects each dev-build, it's beneficial to get rid of unused code as soon as possible. Other possibility is to have some is CI flag, so it would be executed only for CI builds

Copy link
Contributor

Choose a reason for hiding this comment

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

@CuiYifeng, I think we should always follow the rule during daily development, as I don't quite understand the logic behind unused variables. What's the motivation in your mind to bypass the logic for regular development?

@Silv3S Silv3S requested a review from Copilot September 19, 2025 15:32
Copy link
Contributor

@Copilot 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

Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Copy link
Contributor

@EikanWang EikanWang left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -25,6 +25,9 @@ set(PROJECT_VERSION "2.3.0")
# Avoid SYCL compiler error
if(NOT WIN32)
string(APPEND CMAKE_CXX_FLAGS " -Wno-error")
if("$ENV{IS_XPU_CI}" STREQUAL "1")
string(APPEND CMAKE_CXX_FLAGS " -Werror=unused-variable")
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we always turn on this build option?

@EikanWang EikanWang requested a review from CuiYifeng September 19, 2025 18:07
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.

4 participants