Skip to main content

# torch2transformer

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.2.tar.gz (3.7 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.2-py3-none-any.whl (4.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: torch2transformer-0.1.2.tar.gz
  • Upload date:
  • Size: 3.7 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.2.tar.gz
Algorithm Hash digest
SHA256 911de38888ea741302b805b7b1a09343bb89c5e58771d10091e68e27c987602e
MD5 fc8cdbc54e1cc5dd1e75e93015969be7
BLAKE2b-256 d8d3ede64075d2a34768ff442c6598063c2c0456c541492c83b727cc1fdde70d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for torch2transformer-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 990fbba48d37279672228dc02a8b66946691bd13b11464ebe4d07b050bd77286
MD5 73224433253988b3349a88c65804ad6d
BLAKE2b-256 e479d40b4e9af60a7a4c8c6484b3d8e6c5a37c46e459ce12f21b55665eb2ed35

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