XTRAIN: a tiny library for training Flax models.
Design goals:
- Help avoiding boiler-plate code
- Minimal functionality and dependency
- Agnostic to hardware configuration (e.g. GPU->TPU)
General workflow
Step 1: define your model
class MyFlaxModule(nn.Module):
@nn.compact
def __call__(self, x):
...
Step 2: define loss function
def my_loss_func(batch, prediction):
x, y_true = batch
loss = ....
return loss
Step 3: create an iterator that supplies training data
my_data = zip(sequence_of_inputs, sequence_of_labels)
Step 4: train
# create and initialize a Trainer object
trainer = xtrain.Trainer(
model = MyFlaxModule(),
losses = my_loss_func,
optimizer = optax.adam(1e-4),
)
train_iter = trainer.train(my_data) # returns a iterable object
# iterate the train_iter trains the model
for epoch in range(3):
for model_out in train_iter:
pass
print(train_iter.loss_logs)
train_iter.reset_loss_logs()
Training data format
- tensowflow Dataset
- torch dataloader
- generator function
- other python iterable that produce numpy data
Checkpointing
train_iter is orbax compatible.
import orbax.checkpoint as ocp
ocp.StandardCheckpointer().save(cp_path, args=ocp.args.StandardSave(train_iter))
Freeze submodule
train_iter.freeze("submodule/Dense_0/kernel")
Simple batch parallelism on multiple device
# Add a new batch dim to you dataset
ds = ds.batch(8)
# create trainer with the Distributed strategy
trainer_iter = xtrain.Trainer(model, losses, optimizer, strategy=xtrain.Distributed).train(ds)
API documentation
Metadata
Release files for xtrain 0.4.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| xtrain-0.4.3.tar.gz | 12.8 kB | Without provenance | Details for xtrain-0.4.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| xtrain-0.4.3-py3-none-any.whl | Python 3 | none | any | Details for xtrain-0.4.3-py3-none-any.whl |
Total release size: 27.2 kB
Release files / xtrain-0.4.3.tar.gz
| Download URL | xtrain-0.4.3.tar.gz |
|---|---|
| Size | 12.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3793ae065a67dc85b54e557b121c2b323093b278bc120e150a0426440b654d31
|
|
BLAKE2b-256 checksum How to use checksums |
4e1c5e866f402e07463a2acbbecfa2c4f9e038ec2b0f39b83f2bd705d8918da2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.5 CPython/3.10.15 Linux/6.8.0-1017-azure
|
Release files / xtrain-0.4.3-py3-none-any.whl
| Download URL | xtrain-0.4.3-py3-none-any.whl |
|---|---|
| Size | 14.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5dba9a035af9c7355246305b2ecf5b43602768ae4e8553b983cc5c22cef928a3
|
|
BLAKE2b-256 checksum How to use checksums |
486ae9e407f49be9b92d65429c81042a8eb5b3333ca4c5482c797ec37581ad24
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.5 CPython/3.10.15 Linux/6.8.0-1017-azure
|
Security for xtrain 0.4.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.