Skip to content

Conversation

@bagustris
Copy link

This PR will make the main example works again given the depreciation of torchtext.

Copilot AI and others added 14 commits November 20, 2025 09:44
Co-authored-by: bagustris <3158361+bagustris@users.noreply.github.com>
…lity note

Co-authored-by: bagustris <3158361+bagustris@users.noreply.github.com>
…e-usage

Replace deprecated torchtext with standalone GloVe loader
…tibility

Co-authored-by: bagustris <3158361+bagustris@users.noreply.github.com>
Co-authored-by: bagustris <3158361+bagustris@users.noreply.github.com>
…dates

Co-authored-by: bagustris <3158361+bagustris@users.noreply.github.com>
Co-authored-by: bagustris <3158361+bagustris@users.noreply.github.com>
Comment out Codecov upload step in workflow
Fix torch.load calls for PyTorch 2.6+ compatibility
Copilot AI review requested due to automatic review settings December 22, 2025 05:30
Copy link

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 addresses the deprecation of torchtext by implementing two key changes: adding weights_only=False to all torch.load() calls to comply with PyTorch 2.6+ security requirements, and introducing a standalone GloVe embeddings loader to replace the deprecated torchtext.vocab.GloVe functionality.

Key Changes:

  • Added weights_only=False parameter to 200+ torch.load calls across examples, tests, and utilities
  • Implemented new datasets/affect/glove_loader.py with automatic fallback from torchtext
  • Relaxed test tolerances in test_objective_fns.py and test_fusion.py to accommodate numerical variations
  • Updated CI/CD workflows to Python 3.10 and added new docs deployment workflow

Reviewed changes

Copilot reviewed 204 out of 204 changed files in this pull request and generated 11 comments.

Show a summary per file
File Description
tests/test_objective_fns.py Updated exception handling to accept ValueError; increased numerical tolerances
tests/test_integration.py Added weights_only=False to all torch.load calls in integration tests
tests/test_fusion.py Increased rtol values for numerical assertions
datasets/affect/glove_loader.py New standalone GloVe loader with download, caching, and torchtext-compatible API
datasets/affect/get_data.py Added try/except fallback to use glove_loader when torchtext unavailable
datasets/affect/get_raw_data.py Added try/except fallback to use glove_loader when torchtext unavailable
datasets/affect/GLOVE_README.md Documentation for the new GloVe loader functionality
examples/Multibench_Example_Usage.py New standalone example script demonstrating basic usage
examples/Multibench_Example_Usage_Colab.ipynb Added note about torchtext compatibility
.github/workflows/workflow.yml Updated to Python 3.10, commented out codecov upload
.github/workflows/docs.yml New workflow for Sphinx documentation deployment
.github/copilot-instructions.md New AI coding assistant instructions for the project
All other files Added weights_only=False to torch.load calls

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

Comment on lines +80 to +81
try:
urllib.request.urlretrieve(url, zip_file)
Copy link

Copilot AI Dec 22, 2025

Choose a reason for hiding this comment

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

The download lacks progress indication and timeout handling. Consider adding a progress bar using tqdm or urllib's reporthook parameter, and setting a reasonable timeout to prevent indefinite hangs on slow/broken connections.

Copilot uses AI. Check for mistakes.
Comment on lines +117 to +119
# Verify dimension
if len(vector) != self.dim:
continue
Copy link

Copilot AI Dec 22, 2025

Choose a reason for hiding this comment

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

The embedding file dimension verification on line 118 silently skips lines with incorrect dimensions using continue. This could lead to confusion if the wrong file is loaded (e.g., requesting 300d but loading 200d file). Consider raising an error if too many lines are skipped or if the first line has the wrong dimension.

Copilot uses AI. Check for mistakes.
out = fusion([data[0],data[1],data[2]])
assert out.shape == (32,50,1)
assert np.isclose(torch.norm(out).item(), 21.332000732421875)
assert np.isclose(torch.norm(out).item(), 21.332000732421875, rtol=0.15)
Copy link

Copilot AI Dec 22, 2025

Choose a reason for hiding this comment

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

The tolerance value rtol=0.15 (15%) is extremely loose for a numerical test. This suggests either significant non-determinism in the computation or that the expected value may need to be updated. Consider investigating why such a large tolerance is needed and documenting the reason.

Copilot uses AI. Check for mistakes.
uses: actions/setup-python@master
with:
python-version: 3.7
python-version: '3.10'
Copy link

Copilot AI Dec 22, 2025

Choose a reason for hiding this comment

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

The workflow is pinning to Python 3.10 but should specify a patch version for better reproducibility (e.g., '3.10.x' or '3.10.12'). Also consider testing against multiple Python versions if the library supports them, or document that only 3.10 is supported.

Copilot uses AI. Check for mistakes.
Comment on lines +24 to +35
# - name: Upload coverage to Codecov
# uses: codecov/codecov-action@v2
# with:
# token: ${{ secrets.CODECOV_TOKEN }}
# directory: ./coverage/reports/
# env_vars: OS,PYTHON
# fail_ci_if_error: true
# files: ./coverage.xml,./coverage2.xml
# flags: unittests
# name: codecov-umbrella
# path_to_write_report: ./coverage/codecov_report.txt
# verbose: true
Copy link

Copilot AI Dec 22, 2025

Choose a reason for hiding this comment

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

Commenting out the codecov upload rather than removing it entirely creates clutter. If codecov is no longer needed, remove the commented code. If it's temporarily disabled, add a comment explaining why and when it will be re-enabled.

Copilot uses AI. Check for mistakes.
inputs = [torch.rand((1,10,10)).to(device),torch.rand((1,10,10)).to(device)]
inputs_len = torch.tensor([[10],[10]])
assert np.isclose(rgl(logits, (inputs, inputs_len)).item(),0.004487053025513887)
assert np.isclose(rgl(logits, (inputs, inputs_len)).item(), 0.004487053025513887, rtol=0.05)
Copy link

Copilot AI Dec 22, 2025

Choose a reason for hiding this comment

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

Using rtol=0.05 (5% tolerance) is quite loose for a numerical test. Consider if this tolerance is necessary or if the underlying computation has become less deterministic. If the relaxed tolerance is intentional due to platform differences or PyTorch version changes, add a comment explaining why.

Copilot uses AI. Check for mistakes.

self._load_embeddings()

def _get_embedding_file_name(self):
Copy link

Copilot AI Dec 22, 2025

Choose a reason for hiding this comment

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

Missing type hints for return values. The function should specify -> str as the return type for better code documentation and type checking.

Suggested change
def _get_embedding_file_name(self):
def _get_embedding_file_name(self) -> str:

Copilot uses AI. Check for mistakes.

return embedding_file
except Exception as e:
print(f"Error downloading GloVe embeddings: {e}")
Copy link

Copilot AI Dec 22, 2025

Choose a reason for hiding this comment

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

If an exception occurs during download after the zip file is partially created, the incomplete zip file will remain in the cache directory. This could cause extraction failures on subsequent runs. Consider wrapping the download/extract in a try-finally block that removes the zip file if it exists and an error occurred, or checking file integrity before extraction.

Suggested change
print(f"Error downloading GloVe embeddings: {e}")
print(f"Error downloading GloVe embeddings: {e}")
# Remove potentially corrupted or partial zip file
if os.path.exists(zip_file):
try:
os.remove(zip_file)
except OSError:
# If cleanup fails, we still want to surface the original error
pass

Copilot uses AI. Check for mistakes.
Comment on lines +103 to +105
# First pass: count lines to pre-allocate array
with open(embedding_file, 'r', encoding='utf-8') as f:
num_words = sum(1 for _ in f)
Copy link

Copilot AI Dec 22, 2025

Choose a reason for hiding this comment

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

Variable num_words is not used.

Suggested change
# First pass: count lines to pre-allocate array
with open(embedding_file, 'r', encoding='utf-8') as f:
num_words = sum(1 for _ in f)
# First pass: read all lines (was previously used to count for pre-allocation)
with open(embedding_file, 'r', encoding='utf-8') as f:
sum(1 for _ in f)

Copilot uses AI. Check for mistakes.
import zipfile
import urllib.request
from pathlib import Path
import numpy as np
Copy link

Copilot AI Dec 22, 2025

Choose a reason for hiding this comment

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

Import of 'np' is not used.

Suggested change
import numpy as np

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.

1 participant