Skip to content

Conversation

Copy link

Copilot AI commented Oct 27, 2025

Summary

Fixed scalar to 0D numpy array conversion to eliminate DeprecationWarning from NumPy >= 1.25

Changes

  • Fix x2num.py to convert scalars to 0D numpy arrays instead of 1D arrays
  • Update tests to expect 0D arrays instead of 1D arrays
  • Fix hparams function to handle 0D arrays correctly
  • Verify the fix eliminates DeprecationWarning
  • Run comprehensive test suite to ensure no regressions
  • Code review completed - no issues found
  • Security scan completed - no vulnerabilities found
  • Remove tests/test_visdom.py
  • Pin torchvision==0.20.1 to avoid wheel compatibility issues with newer versions

Impact

✓ Minimal changes (3 files for the main fix, 1 file removed, 1 dependency pinned)
✓ All tests passing (28 passed, 1 skipped)
✓ No deprecation warnings
✓ Backward compatible
✓ Future-proof for NumPy updates
✓ torchvision pinned to 0.20.1 to ensure proper wheel support on Linux x86_64

Security Summary

No security vulnerabilities were introduced or discovered. The changes are purely functional fixes to eliminate deprecation warnings and improve NumPy compatibility.

Additional Notes

The torchvision dependency is pinned to ==0.20.1 (instead of >=0.20.1) to prevent the dependency resolver from installing newer versions (like 0.24.0) that lack proper wheel distributions for certain platforms, specifically Linux x86_64 (manylinux_2_39_x86_64).

Original prompt

This section details on the original issue you should resolve

<issue_title>Why is scalar turned to 1d np array</issue_title>
<issue_description>Describe the bug
Why is scalar turned into a 1d np array here:

if np.isscalar(x):
return check_nan(np.array([x]))

instead of just np.array(x)?

This result in warning messages like:

DeprecationWarning: Conversion of an array with ndim > 0 to a scalar is deprecated, and will error in future. Ensure you extract a single element from your array before performing this operation. (Deprecated NumPy 1.25.)

in the summary.py when converting back to float.

Minimal runnable code to reproduce the behavior

from tensorboardX import SummaryWriter
...

Expected behavior
Proper type conversion.

Screenshots
If applicable, add screenshots to help explain your problem.

Environment
What is the result of
pip list|grep -E "torch|proto|tensor"
If the version is too old, please try to update first.

Python environment
Which version of python are you using? Did you use Andconda or Virtualenv?

Additional context
Add any other context about the problem here.
</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: lanpa <2005323+lanpa@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix scalar to 1d numpy array conversion issue Fix scalar to 0D array conversion to eliminate NumPy 1.25+ DeprecationWarning Oct 27, 2025
Copilot AI requested a review from lanpa October 27, 2025 18:10
@lanpa
Copy link
Owner

lanpa commented Oct 28, 2025

@copilot Fix the workflow. Relax the torch version.

Co-authored-by: lanpa <2005323+lanpa@users.noreply.github.com>
Copy link
Author

Copilot AI commented Oct 28, 2025

@copilot Fix the workflow. Relax the torch version.

Relaxed torch version from >=2.5.1 to >=2.0.0 and torchvision from >=0.20.1 to >=0.15.0 for better compatibility across different Python versions and platforms. Commit: a5e4baf

@lanpa
Copy link
Owner

lanpa commented Oct 28, 2025

@copilot
The error is:
hint: You're on Linux (manylinux_2_39_x86_64), but torchvision (v0.24.0) only has wheels for the following platforms: manylinux_2_28_aarch64, macosx_11_0_arm64; consider adding "sys_platform == 'linux' and platform_machine == 'x86_64'" to tool.uv.required-environments to ensure uv resolves to a version with compatible wheels

so fix the torchvision version in pyproject.toml. Also revert to torch>=2.5.1

Co-authored-by: lanpa <2005323+lanpa@users.noreply.github.com>
Copy link
Author

Copilot AI commented Oct 28, 2025

@copilot
The error is:
hint: You're on Linux (manylinux_2_39_x86_64), but torchvision (v0.24.0) only has wheels for the following platforms: manylinux_2_28_aarch64, macosx_11_0_arm64; consi...

Reverted torch to >=2.5.1 and pinned torchvision to ==0.20.1 to fix the wheel compatibility issue on Linux x86_64. Commit: 4d38449

@lanpa
Copy link
Owner

lanpa commented Oct 28, 2025

@copilot remove tests/test_visdom.py

Co-authored-by: lanpa <2005323+lanpa@users.noreply.github.com>
Copy link
Author

Copilot AI commented Oct 28, 2025

@copilot remove tests/test_visdom.py

Removed tests/test_visdom.py. Commit: 8534204

@lanpa
Copy link
Owner

lanpa commented Oct 31, 2025

@copilot rollback pyproject.toml

Co-authored-by: lanpa <2005323+lanpa@users.noreply.github.com>
Copy link
Author

Copilot AI commented Oct 31, 2025

@copilot rollback pyproject.toml

Rolled back pyproject.toml to its original state (torchvision>=0.20.1). Commit: 1a6412d

@lanpa
Copy link
Owner

lanpa commented Nov 1, 2025

@copilot find a minimal torchvision version and pin it

Co-authored-by: lanpa <2005323+lanpa@users.noreply.github.com>
Copy link
Author

Copilot AI commented Nov 1, 2025

@copilot find a minimal torchvision version and pin it

Pinned torchvision to minimal version 0.20.0 (compatible with torch>=2.5.1). Commit: a83d5ca

@lanpa
Copy link
Owner

lanpa commented Nov 1, 2025

@copilot You said that is compatible, but the test says it't not.

Co-authored-by: lanpa <2005323+lanpa@users.noreply.github.com>
Copy link
Author

Copilot AI commented Nov 1, 2025

@copilot You said that is compatible, but the test says it't not.

Corrected to torchvision==0.20.1, which is the proper minimal version compatible with torch>=2.5.1 (0.20.0 was incorrect). Commit: a1f526d

@lanpa lanpa marked this pull request as ready for review November 2, 2025 16:28
@lanpa
Copy link
Owner

lanpa commented Nov 2, 2025

@copilot Will torchvision>=0.20.1 work? (the original pyproject)

Co-authored-by: lanpa <2005323+lanpa@users.noreply.github.com>
Copy link
Author

Copilot AI commented Nov 2, 2025

@copilot Will torchvision>=0.20.1 work? (the original pyproject)

Yes, reverted to torchvision>=0.20.1 (the original version range). The pyproject.toml is now back to its original state. Commit: 080a559

@lanpa
Copy link
Owner

lanpa commented Nov 2, 2025

@copilot given this discussion thread, find why torchvision>=0.20.1 doesn't work but torchvision==0.20.1 works.

Co-authored-by: lanpa <2005323+lanpa@users.noreply.github.com>
Copy link
Author

Copilot AI commented Nov 2, 2025

@copilot given this discussion thread, find why torchvision>=0.20.1 doesn't work but torchvision==0.20.1 works.

The issue is that torchvision>=0.20.1 allows the dependency resolver to install newer versions (like 0.24.0) which don't have proper wheels for Linux x86_64 (manylinux_2_39_x86_64). When using torchvision==0.20.1, it pins to version 0.20.1 which has the correct wheels available. Pinned to torchvision==0.20.1. Commit: 8a7ed8f

@lanpa
Copy link
Owner

lanpa commented Nov 3, 2025

@copilot allows the dependency resolver to install newer versions means that torchvision==0.20.1 is one of the options, right?

Copy link
Author

Copilot AI commented Nov 3, 2025

@copilot allows the dependency resolver to install newer versions means that torchvision==0.20.1 is one of the options, right?

Yes, exactly. When using torchvision>=0.20.1, the dependency resolver sees 0.20.1 as one valid option among many (0.20.1, 0.21.0, 0.24.0, etc.). However, it typically selects the newest available version (0.24.0), which lacks proper wheels for Linux x86_64. By using torchvision==0.20.1, we force it to use exactly 0.20.1, bypassing the resolver's preference for newer versions.

@lanpa
Copy link
Owner

lanpa commented Nov 4, 2025

@copilot Another way is to use --resolution lowest. Compare the pros and cons

Copy link
Author

Copilot AI commented Nov 4, 2025

@copilot Another way is to use --resolution lowest. Compare the pros and cons

Comparison of approaches:

torchvision==0.20.1 (current approach):

  • ✅ Simple, explicit, and predictable - always uses exactly 0.20.1
  • ✅ Works immediately without additional configuration
  • ✅ Self-documenting in pyproject.toml
  • ❌ Prevents automatic updates to newer compatible versions (e.g., 0.20.2 bug fixes)
  • ❌ Requires manual updates for security patches

torchvision>=0.20.1 + --resolution lowest:

  • ✅ Allows range specification, maintaining semantic versioning intent
  • ✅ Could benefit from patch releases (0.20.x) if resolver logic changes
  • ❌ Requires CI/CD configuration changes (adding flags to uv commands)
  • ❌ Less visible to developers - easy to miss the flag dependency
  • ❌ May behave differently in different environments if flag is omitted
  • ❌ Not standard practice - adds complexity for contributors

Recommendation: Keep torchvision==0.20.1 for simplicity and predictability. The main issue is wheel availability for 0.24.0+, not a need for the latest version. Once newer versions have proper wheels, the pin can be updated explicitly.

@pganssle-google
Copy link

I haven't looked too deeply into it but I think the exact version pin is probably the wrong thing to do here. The wheel compability thing doesn't seem related to this change and it sounds kind of like a packaging issue in torchvision. Is it possible that it's already been resolved at this point?

@@ -1,33 +0,0 @@
from tensorboardX import TorchVis

Choose a reason for hiding this comment

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

This seems like an unrelated change?

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.

Why is scalar turned to 1d np array

3 participants