Skip to main content

Overview

DeTrain is a Python package designed to train AI models using model parallelism methods. This package focuses on pipeline and tensor parallelism.

Installation

You can install DeTrain using pip:

pip install detrain

Usage

Once installed, you can use DeTrain in your Python scripts like this:

import torch.nn as nn
import torch
import time
import os
from detrain.ppl.args_util import get_args
from detrain.ppl.worker import run_worker
from detrain.ppl.dataset_util import get_torchvision_dataset
from shards_model import NNShard1, NNShard2
import torch.optim as optim

if __name__=="__main__":
    args = get_args()
    # Get args
    world_size = int(os.environ["WORLD_SIZE"])
    rank = int(os.environ["RANK"])
    epochs = int(args.epochs)
    batch_size = int(args.batch_size)
    lr = float(args.lr)

    for i in range(torch.cuda.device_count()):
        print(torch.cuda.get_device_properties(i).name)

    devices = []
    workers = []
    shards = [NNShard1, NNShard2]
    # Check devices
    if (args.gpu is not None):
        arr = args.gpu.split('_')
        for dv in range(len(arr)):
            if dv > 0:
                workers.append(f"worker{dv}")
                if int(arr[dv]) == 1:
                    devices.append("cuda:0")
                else:
                    devices.append("cpu")

    # Define optimizer & loss_fn
    loss_fn = nn.CrossEntropyLoss()
    optimizer_class = optim.SGD

    # Dataloaders

    (train_dataloader, test_dataloader) = get_torchvision_dataset("MNIST", batch_size)


    print(f"World_size: {world_size}, Rank: {rank}")

    num_split = 4
    tik = time.time()
    run_worker(
        rank,
        world_size,
        (
            args.split_size,
            workers,
            devices,
            shards
        ),
        train_dataloader,
        test_dataloader,
        loss_fn,
        optimizer_class,
        epochs,
        batch_size,
        lr
    )
    tok = time.time()
    print(f"number of splits = {num_split}, execution time = {tok - tik}")

For detailed examples, please visit the DeTrain examples.

Contributing

Contributions are welcome! If you’d like to contribute to DeTrain, please follow these steps:

  1. Fork the repository on GitHub.

  2. Create a new branch.

  3. Make your changes and commit them with clear descriptions.

  4. Push your changes to your fork.

  5. Submit a pull request.

Bug Reports and Feedback

If you encounter any bugs or have feedback, please open an issue on the GitHub repository.

License

DeTrain is licensed under the MIT License. See the LICENSE file for more information.

Metadata

Release files for detrain 0.2.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for detrain 0.2.6
File Size Uploaded
detrain-0.2.6.tar.gz 15.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for detrain 0.2.6
File Interpreter ABI Platform
detrain-0.2.6-py3-none-any.whl Python 3 none any Details

Total release size: 32.2 kB

Release files / detrain-0.2.6.tar.gz

Download URL detrain-0.2.6.tar.gz
Size 15.7 kB
Tags Source
SHA-256 checksum
How to use checksums
6c88ffc326013aeeaa675aee365af335be7ee8f50799e7eeb66acf13e8b95df2
BLAKE2b-256 checksum
How to use checksums
a79153324575d8608d11920d0b4e647c31ae16c51540af4387973771140dc81e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.10.12

Release files / detrain-0.2.6-py3-none-any.whl

Download URL detrain-0.2.6-py3-none-any.whl
Size 16.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
651bd12301a8011746797eef64a7a3a9c838f0d44b622f5e7aec8cdb0415a40e
BLAKE2b-256 checksum
How to use checksums
75c648a5fbef3722ceeb979b0c6991e3744540cbd94d4d3e05c1c0ea0737d1f1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.10.12

Release history Release notifications | RSS feed

This release

0.2.6 This release

2 release files

0.2.5

2 release files

0.2.4

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page