Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@kitsuyaazuma
Copy link
Collaborator

WHAT

This PR moves the torch.multiprocessing import from the global scope of client_trainer.py to the inside of the ProcessPoolClientTrainer.local_process method.

WHY

The global import was causing

/root/.local/share/uv/python/cpython-3.14.0+freethreaded-linux-x86_64-gnu/lib/python3.14t/multiprocessing/resource_tracker.py:297: UserWarning: resource_tracker: There appear to be 1 leaked semaphore objects to clean up at shutdown: {'/mp-qsttc0lg'}
  warnings.warn(

for users of ThreadPoolClientTrainer (which does not use multiprocessing).

This change ensures that torch.multiprocessing and its associated resources are only initialized when ProcessPoolClientTrainer is actually used, resolving the leak warning for ThreadPoolClientTrainer users.

@kitsuyaazuma kitsuyaazuma requested a review from Copilot November 4, 2025 04:56
Copy link
Contributor

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 updates dependency lock files and makes several code improvements focused on import ordering, API usage fixes, and performance optimization. The changes ensure better compatibility with PyTorch's API requirements and improve code organization following import sorting best practices.

  • Updates the uv.lock file to add new dependencies for workspace examples (gitpython, pillow, protobuf, pydantic, torchvision, wandb, etc.)
  • Fixes PyTorch CUDA tensor creation and RNG forking API usage
  • Optimizes import loading by moving torch.multiprocessing import to where it's used
  • Standardizes import order to place third-party imports before local imports

Reviewed Changes

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

Show a summary per file
File Description
uv.lock Adds new dependencies and workspace members for quickstart and step-by-step examples
tests/test_reproducibility/test_generator.py Adds device="cuda" parameter to CUDA tensor creation for proper device placement
src/blazefl/core/client_trainer.py Moves torch.multiprocessing import to local scope for deferred loading
examples/step-by-step-dsfl/pyproject.toml Configures ruff to treat wandb as third-party import
examples/step-by-step-dsfl/models/selector.py Fixes torch.random.fork_rng() to pass empty list argument
examples/step-by-step-dsfl/main.py Reorders imports to place wandb before local imports
examples/quickstart-fedavg/pyproject.toml Configures ruff to treat wandb as third-party import
examples/quickstart-fedavg/models/selector.py Fixes torch.random.fork_rng() to pass empty list argument
examples/quickstart-fedavg/main.py Reorders imports to place wandb before local imports

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

@kitsuyaazuma kitsuyaazuma merged commit de39a1e into main Nov 4, 2025
1 check passed
@kitsuyaazuma kitsuyaazuma deleted the fix/lazy-import-mp branch November 4, 2025 05:09
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