Skip to main content

Stochastic bfloat16 based optimizer library.

Project description

torchastic

stochastic bfloat16 based optimizer library

How to Use

import torch
import torch.nn as nn
from torchastic import Compass, StochasticAccumulator


class Model(nn.Module):
    ...


# Init model
model = Model(*model_args)
optimizer = Compass(model.parameters(), lr=0.01, weight_decay=1e-2, amp_fac=5)

# Apply stochastic grad accumulator hooks
StochasticAccumulator.assign_hooks(model)

# Training
while True:

    # Gradient accumulation
    for _ in range(grad_accum_length):
        with torch.autocast(device_type="cuda", dtype=torch.bfloat16):
            loss = model.loss(*model_input)
        loss.backward()

    # Apply grad buffer back
    StochasticAccumulator.reassign_grad_buffer(model)
    optimizer.step()
    optimizer.zero_grad()

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

torchastic-0.1.1.tar.gz (8.5 kB view details)

Uploaded Source

Built Distribution

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

torchastic-0.1.1-py3-none-any.whl (8.7 kB view details)

Uploaded Python 3

File details

Details for the file torchastic-0.1.1.tar.gz.

File metadata

  • Download URL: torchastic-0.1.1.tar.gz
  • Upload date:
  • Size: 8.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.6

File hashes

Hashes for torchastic-0.1.1.tar.gz
Algorithm Hash digest
SHA256 90967fa393d9a516eee096e97c709b9c016244e5794201900e31afcbc3c99a33
MD5 1cfa9862cd16d14b48aa3477a087f2dc
BLAKE2b-256 5954c9c8598f144ec31bc870589ff4668b65bc005b69305eae4d1db962acdb09

See more details on using hashes here.

File details

Details for the file torchastic-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: torchastic-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 8.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.6

File hashes

Hashes for torchastic-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 49cab37bc474f3127e2d05a87db5d06f3c5069e9090d5655d8413f096ab73b13
MD5 fcddd9c686299bca3a99a8583b2950bd
BLAKE2b-256 362d4265e5496f7567cb94bf8744b5ed60d1280d652d43b6e7e1ca463ccb3f8d

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