Skip to main content

This is an extension to pystematic that adds functionality related to running machine learning experiments in pytorch. Its main contribution is the Context object and related classes. Which provides an easy way to manage all pytorch related objects.

Installation

All you have to do for pystematic to find the plugin is to install it:

$ pip install pystematic-torch

Example

Here’s a small example that shows how using the Context object, SmartDataLoader and Recorder simplifies setting up and running a training session in pytorch.

import pystematic

@pystematic.experiment
def context_example(params):
    ctx = pystematic.torch.Context()

    ctx.epoch = 0

    ctx.recorder = pystematic.torch.Recorder()

    ctx.model = torch.nn.Sequential(
        torch.nn.Linear(2, 1),
        torch.nn.Sigmoid()
    )

    ctx.optimzer = torch.optim.SGD(ctx.model.parameters(), lr=0.01)

    # We use the smart dataloader so that batches are moved to
    # the correct device
    ctx.dataloader = pystematic.torch.SmartDataLoader(
        dataset=Dataset(),
        batch_size=2
    )
    ctx.loss_function = torch.nn.BCELoss()

    ctx.cuda() # Move everything to cuda
    # ctx.ddp() # and maybe distributed data-parallel?

    if params["checkpoint"]:
        # Load checkpoint
        ctx.load_state_dict(pystematic.torch.load_checkpoint(params["checkpoint"]))

    # Train one epoch
    for input, lbl in ctx.dataloader:
        # The smart dataloader makes sure the batch is placed on
        # the correct device.
        output = ctx.model(input)

        loss = ctx.loss_function(output, lbl)

        ctx.optimzer.zero_grad()
        loss.backward()
        ctx.optimzer.step()

        ctx.recorder.scalar("train/loss", loss)
        ctx.recorder.step()

    ctx.epoch += 1

    # Save checkpoint
    pystematic.torch.save_checkpoint(ctx.state_dict(), id=ctx.epoch)

Documentation

Reference documentation is available at https://pystematic-torch.readthedocs.io.

Metadata

Release files for pystematic-torch 1.3.4

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

Built distribution (wheel)

Table of built distributions (wheels) for pystematic-torch 1.3.4
File Interpreter ABI Platform
pystematic_torch-1.3.4-py3-none-any.whl Python 3 none any Details

Release files / pystematic_torch-1.3.4-py3-none-any.whl

Download URL pystematic_torch-1.3.4-py3-none-any.whl
Size 13.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
93e1a5b3c4a59713e6a6bd576b38773d39ac489ef36ecfebfa147043e47ce15b
BLAKE2b-256 checksum
How to use checksums
e8d87810f5ef7cc9279ffb012aea53229634ca75559352ab75b38ab6d37ff2d2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.2.2 CPython/3.8.16 Linux/5.15.0-1031-azure

Release history Release notifications | RSS feed

This release

1.3.4 This release

1 release file

1.3.3

1 release file

1.3.2

1 release file

1.3.1

1 release file

1.3.0

1 release file

1.2.0

1 release file

1.1.0

1 release file

1.0.0

1 release file

0.1.2

1 release file

0.1.1

1 release file

0.1.0

1 release file

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