Skip to main content

Wrap plain PyTorch models for the Hugging Face Transformers ecosystem

Project description

torch2transformer

torch2transformer lets you wrap plain PyTorch models so they work seamlessly with the Hugging Face Transformers ecosystem. Important note: The original PyTorch model class must be available at run time and load time.

Features

  • Use Trainer with any PyTorch model
  • Save / load via save_pretrained
  • Minimal adapter interface
  • No custom training loops

Example

from torch2transformer import TorchAdapter, wrap_model, load_model

# wrap Pytorch model as a Transformer model
model = wrap_model(
    torch_model_cls=TinyCharModel,
    torch_model_kwargs={"vocab_size": 100, "hidden_size": 32},
    task_type="causal_lm"
)
# then can be used with Trainer()

# save model
model.save_pretrained("./tiny_ckpt")

# load model
model = load_model("./tiny_ckpt", torch_model_cls=TinyCharModel)

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

torch2transformer-0.1.0.tar.gz (3.3 kB view details)

Uploaded Source

Built Distribution

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

torch2transformer-0.1.0-py3-none-any.whl (4.4 kB view details)

Uploaded Python 3

File details

Details for the file torch2transformer-0.1.0.tar.gz.

File metadata

  • Download URL: torch2transformer-0.1.0.tar.gz
  • Upload date:
  • Size: 3.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for torch2transformer-0.1.0.tar.gz
Algorithm Hash digest
SHA256 08185b6f3029aae5c2399809631df1931a1058afb9ebaae71ef6272ec8b7b5cc
MD5 aecb8ebe65b1c1970f1ea417431c9398
BLAKE2b-256 a6b26456feb44952844133068a00af8279c8eb486795de7abdd74478c20c2fd7

See more details on using hashes here.

File details

Details for the file torch2transformer-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for torch2transformer-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3dd2432892d41e30ce75561949c10a8329111f3e032fefbcf7c463ce92fdeaa2
MD5 a79cdbfc3a1d6a27ac3ae637e6184f69
BLAKE2b-256 3c6f07def65ca318297dff2d16586cec78de0f9249c1e3e2e342fefc3eba0418

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