Skip to main content

matorage

Build Status Documentation Status License: Apache 2.0 PyPI Downloads Code style: black

An efficient way to store/load and manage dataset, model and optimizer for deep learning with matorage!

Matorage is tensor(multidimensional matrix) object storage manager for deep learning framework(Pytorch, Tensorflow V2, Keras).

Features

  • Boilerplated data pipeline for dataset, model and optimizer.
  • High performance on tensor storage

For researchers who need to focus on model training:

  • Support storing data in pre-processed Tensor(multidimensional matrix), eliminate training time.
  • Reduce storage space through multiple compression methods.
  • Manage data and models while training

For AI Developer who need to focus on creating data pipeline:

  • Concurrency data save & load
  • Compatible with object storage such as MinIO, S3
  • Generate pipeline from user endpoints data.

Quick Start with Pytorch Example

For an example of tensorflow, refer to the detailed document. If you want to see the full code, see below

0. Install matorage with pip

$ pip install matorage

1. Set up Minio Server with docker

quick start with NAS(network access storage) using docker It can be managed through the web through the address http://127.0.0.1:9000/, and security is managed through MINIO_ACCESS_KEY and MINIO_SECRET_KEY.

$ mkdir ~/shared # create nas storage folder
$ docker run -it -p 9000:9000 \
    --restart always -e \
    "MINIO_ACCESS_KEY=minio" -e \
    "MINIO_SECRET_KEY=miniosecretkey" \
    -v ~/shared:/container/vol \
    minio/minio gateway nas /container/vol

2. Save pre-processed dataset

First, create a DataConfig by importing matorage. This is an example of pre-processing mnist and storing it in distributed storage. additional is freely in the form of a dict, and records the shape and type of tensor to be stored in attributes.

from matorage import DataConfig

traindata_config = DataConfig(
    endpoint='127.0.0.1:9000',
    access_key='minio',
    secret_key='miniosecretkey',
    dataset_name='mnist',
    additional={
        "mode": "train",
        "framework" : "pytorch",
        ...
        "blah" : "blah"
    },
    attributes=[
        ('image', 'float32', (1, 28, 28)),
        ('target', 'int64', (1))
    ]
)

Now do a simple pre-processing and save the data.

from matorage import DataSaver

traindata_saver = DataSaver(config=traindata_config)
train_loader = DataLoader(dataset, batch_size=60, num_workers=8)
for (image, target) in tqdm(train_loader):
    # image shape : torch.Size([64, 1, 28, 28])
    # target shape : torch.Size([64])
    traindata_saver({
        'image': image,
        'target': target
    })
traindata_saver.disconnect()

3. Load dataset from matorage

Now fetch data iteratively from storage with the same config as the saved dataset when training.

from matorage.torch import Dataset

train_dataset = Dataset(config=traindata_config, clear=True)
train_loader = DataLoader(
    train_dataset, batch_size=64, num_workers=8, shuffle=True
)

for batch_idx, (image, target) in enumerate(tqdm(train_loader)):
    image, target = image.to(device), target.to(device)

Only an index can be fetched through lazy load.

train_dataset = Dataset(config=traindata_config, clear=True)
print(train_dataset[0], len(train_dataset))

4. Save & Load Model when training

During training, you can save and load models of specific steps or epochs in distributed storage through inmemory. First, make the model config the same as the dataset.

from matorage import ModelConfig
from matorage.torch import ModelManager

model_config = ModelConfig(
    endpoint='127.0.0.1:9000',
    access_key='minio',
    secret_key='miniosecretkey',
    model_name='mnist_simple_training',
    additional={
        "version" : "1.0.1",
        ...
        "blah" : "blah"
    }
)

model_manager = ModelManager(config=model_config)
print(model_manager.get_metadata)
model_manager.save(model, epoch=1)
print(model_manager.get_metadata)

When an empty model is loaded with specific steps or epochs, the appropriate weight is filled into the model.

print(model.state_dict())
model_manager.load(model, epoch=1)
print(model.state_dict())
# load a layer weight.
print(model_manager.load('net1.0.weight', step=0))

5. Save & Load Optimizer when training

Save and load of optimizer is similar to managing model.

from matorage import OptimizerConfig
from matorage.torch import OptimizerManager

optimizer_config = OptimizerConfig(
    endpoint='127.0.0.1:9000',
    access_key='minio',
    secret_key='miniosecretkey',
    optimizer_name='adam',
    additional={
        "model" : "1.0.1",
        ...
        "blah" : "blah"
    }
)

optimizer_manager = OptimizerManager(config=optimizer_config)
print(optimizer_manager.get_metadata)
# The optimizer contains information about the step.
optimizer_manager.save(optimizer)
print(optimizer_manager.get_metadata)

When an empty optimizer is loaded with specific steps, the appropriate weight is filled into the optimizer.

optimizer = optim.Adam(model.parameters(), lr=0.01)
optimizer_manager.load(optimizer, step=938)

Unittest

$ git clone https://github.com/graykode/matorage && cd matorage
$ python -m tests.test_suite

Framework Requirement

  • torch(>=1.0.0), torchvision(>=0.2.2)
  • tensorflow(>=2.2), tensorflow_io(>=0.13)

Author

Tae Hwan Jung(@graykode) We are looking for a contributor.

Metadata

Release files for matorage 0.3.0

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

Source distribution (sdist)

Source distribution for matorage 0.3.0
File Size Uploaded Provenance Actions
matorage-0.3.0.tar.gz 42.7 kB Without provenance Details for matorage-0.3.0.tar.gz

Built distribution (wheel)

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

Total release size: 122.8 kB

Release files / matorage-0.3.0.tar.gz

Download URL matorage-0.3.0.tar.gz
Size 42.7 kB
Tags Source
SHA-256 checksum
How to use checksums
8bc1901b9a9c7feef6d1e75f322eeff18cbdde5064327b3e62201d2e4adb0674
BLAKE2b-256 checksum
How to use checksums
69663c1f7cf97067029da5007e2976cac75ae021e2c0c35b2ccfaf6399370c2f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.50.0 CPython/3.8.5

Release files / matorage-0.3.0-py3-none-any.whl

Download URL matorage-0.3.0-py3-none-any.whl
Size 80.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
558826982711e481f93b14310ed96f8c001cfaf1142dd7de367a8b4860b06306
BLAKE2b-256 checksum
How to use checksums
430788f300a745d1b56d069a8e363f3ff47f8002f78dcd5e96c9e83119fe7edf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.50.0 CPython/3.8.5

Security for matorage 0.3.0

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.

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