Skip to main content

A hook for torch.distributed ProcessGroup primitives with timeout detection

Project description

Group Collective Communication Hook

A monitoring solution for PyTorch distributed training that hooks into all ProcessGroup collective communication primitives and performs timeout detection in pure Python using multiprocessing to avoid GIL limitations.

Overview

This package provides a robust monitoring mechanism for distributed PyTorch training by:

  • Hooking all ProcessGroup collective communication primitives
  • Implementing timeout detection using a separate process to avoid Python GIL constraints
  • Sending SIGUSR1 signal when timeout is detected
  • No C++ compilation required - pure Python implementation with multiprocessing

PyPI version

Quick Start

Build from Source

# Install the package (no build step needed - pure Python)
pip install .

# Run tests
torchrun --nproc_per_node=4 test_all_reduce.py 

# Test basic hook functionality
torchrun --nproc_per_node=4 test_hook_simple.py

Installation

Install the package using pip:

pip install .

Usage

Add the following code to your training script:

from group_cc_hook import run_daemon, stop_daemon

# Start the monitoring daemon
run_daemon()
 
############################# Your Training Code START #########################

############################# Your Training Code END ###########################

# Stop the monitoring daemon
stop_daemon()

Configuration

You can configure the timeout threshold and other parameters by modifying the run_daemon function call.

from group_cc_hook import HookConfig, run_daemon

# Default: timeout detection with SIGUSR1 signal
run_daemon()

# Custom configuration
config = HookConfig(
    timeout_seconds=600,
    signal_number=12,  # SIGUSR1 (default), change to another signal if needed
    send_signal_on_timeout=True, # Default: True, set to False if you want to handle timeouts in your code
    check_interval_ms=10 # Enabled by default
    
)
run_daemon(config)

Or just use the environment variables directly:

export PG_HOOK_TIMEOUT=600
export PG_HOOK_CHECK_INTERVAL=10
export PG_HOOK_SIGNAL=12
export PG_HOOK_SEND_SIGNAL=1

License

This project is licensed under the MIT License - see the LICENSE file for details.

Project Structure

├── work_monitor.py                                # Pure Python work monitoring and timeout detection
├── config.py                                      # Configuration management   
├── patch_all_collective_primi.py                  # Hooks for ProcessGroup primitives
├── run_daemon.py                                  # Daemon launcher script
├── setup.py                                       # Package setup configuration
├── test_all_reduce.py                             # AllReduce test script
├── test_hook_simple.py                            # Basic hook functionality test
├── README.md                                      # This file
└── doc/                                           # Documentation directory
    ├── DESIGN_ANALYSIS.md                         # Design analysis report
    ├── COMPATIBILITY.md                           # Version compatibility guide
    └── DEBUG_USAGE.md                             # Debug logging instructions

Documentation

Requirements

  • Python: >= 3.7, < 3.13
  • PyTorch: >= 1.8.0, < 3.0.0
  • CUDA: Required for GPU support (if using NCCL backend)
  • Operating System: Linux (or any OS supporting PyTorch distributed)

For detailed compatibility information, please refer to COMPATIBILITY.md.

Development

Running Tests

# Install development dependencies
pip install -r requirements-dev.txt

# Run unit tests
pytest tests/unit/

# Code quality checks
black --check .
flake8 .

release

# Build package
python setup.py sdist bdist_wheel  

# Publish package to PyPI
twine upload dist/*

Contributing

Contributions are welcome! Please feel free to submit Issues and Pull Requests.

Before submitting your code, please ensure:

  • All tests pass
  • Code follows the project style guidelines (Black, Flake8)
  • Documentation is updated if necessary

License

See LICENSE file for details.

Changelog

See CHANGELOG.md for version history and changes.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

group_cc_hook-0.1.2.tar.gz (13.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

group_cc_hook-0.1.2-py3-none-any.whl (20.5 kB view details)

Uploaded Python 3

File details

Details for the file group_cc_hook-0.1.2.tar.gz.

File metadata

  • Download URL: group_cc_hook-0.1.2.tar.gz
  • Upload date:
  • Size: 13.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.2

File hashes

Hashes for group_cc_hook-0.1.2.tar.gz
Algorithm Hash digest
SHA256 ff5693b78d81215035501a6d55e37e1a38315e6669ddaff53a980b0d944fe275
MD5 9a0a6a56b95275a36a62002d65749ce7
BLAKE2b-256 f90918d516418a442b518687bf10836433a244b146ba47690e691162f6fe53e0

See more details on using hashes here.

File details

Details for the file group_cc_hook-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: group_cc_hook-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 20.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.2

File hashes

Hashes for group_cc_hook-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 a407922469c22f160e140ba0522d6bc14dcbce3a9f25e0d42a59ff11ab14c894
MD5 f31641e09c1565a837eca538e333e3be
BLAKE2b-256 232b2d30a5ec9445b2c9a6f517b7fd28ee39f55ec529ceb89af399848f300867

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page