Cycleformers
A Python library for efficient cycle-consistency training of transformer models. Cycleformers simplifies iterative back-translation with support for both causal and seq2seq architectures. We also implement Multi-Adapter Cycle-Consistency Training (MACCT), enabling training of LoRA adapters on a frozen base model for 7.5x larger model capacity for the same memory footprint.
Features
- 🤗 Seamless integration with Hugging Face Transformers
- 🚀 PEFT/LoRA support for memory-efficient training
- 🤖 Compatible with both causal and seq2seq models
- 🔥 Optimized for various hardware configurations
Quick Tour
Installation
pip install cycleformers
Training
The CycleTrainer class is an extension but significant redesign of the 🤗 Transformers trainer, designed to abstract away the specifics of training while remaining configurable. Both Seq2Seq and Causal architectures are supported, each able to train via PEFT adapter swapping for memory efficient configurations. Check the [docs] for [usage] details and [examples].
To train using two identical models the following sample code can be used along with two datasets:
from cycleformers import CycleTrainer, CycleTrainingArguments
model = AutoModelForCausalLM.from_pretrained("gpt2", device_map="auto")
tokenizer = AutoTokenizer.from_pretrained("gpt2")
args = CycleTrainingArguments(output_dir="gpt2-cct")
trainer = CycleTrainer(
args,
models = model
tokenizers = tokenizer
train_dataset_A = dataset_A,
train_dataset_B = dataset_B
)
trainer.train()
Any two models (🚧 currently both seq2seq or both causal) can be combined together for completely customisable training:
model_A = AutoModelForCausalLM.from_pretrained("gpt2", device_map="auto")
model_B = AutoModelForSeq2SeqLM.from_pretrained("google/flan-t5-base", device_map="auto")
tokenizer_A = AutoTokenizer.from_pretrained("gpt2")
tokenizer_B = AutoTokenizer.from_pretrained("google/flan-t5-small")
trainer = CycleTrainer(
args,
models = {
"A": model_A,
"B": model_B
}
tokenizers = {
"A": tokenizer_A,
"B": tokenizer_B
}
train_dataset_A = dataset_A,
train_dataset_B = dataset_B
)
Multi-Adapter Cycle-Consistency Training (MACCT)
The CycleTrainer class is also setup to accept a single base model and train two PEFT adapters ontop of it, switching between them to emulate the two model setup. This allows for the training of 7.5x larger models for the same memory footprint:
peft_config = PeftConfig(
task_type="CAUSAL_LM",
r=16,
lora_alpha=32,
target_modules="all-linear",
inference_mode=False,
bias="none"
)
args = CycleTrainingArguments(output_dir="gpt2-macct")
trainer = CycleTrainer(
args,
model = model,
tokenizer = tokenizer,
peft_configs = peft_config # Or same A, B dict
)
Citing
If you use Cycleformers in your research, please cite:
add once zenodo/paper citation is available
Metadata
Release files for cycleformers 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| cycleformers-0.1.0.tar.gz | 15.7 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| cycleformers-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 31.7 kB
Release files / cycleformers-0.1.0.tar.gz
| Download URL | cycleformers-0.1.0.tar.gz |
|---|---|
| Size | 15.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
23f5985ab08eba95b7106d7d13c7ff3f9f7bd08655564981df63744725dfafb7
|
|
BLAKE2b-256 checksum How to use checksums |
5987bfc7a537a4834d2977d8eab37f710b8c06062e3ee364ef20ccbc3e8a779c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/5.1.1 CPython/3.12.7
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 8, 2024.
Transparency logRelease files / cycleformers-0.1.0-py3-none-any.whl
| Download URL | cycleformers-0.1.0-py3-none-any.whl |
|---|---|
| Size | 16.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
cd05e82ac0654133d0580603bce064ad455ec6a8918a788a42d47e3b9dfa1074
|
|
BLAKE2b-256 checksum How to use checksums |
b309615d7e84df1f24527bdd9499ff3ca3f8f163a95c1c13b1fc00c88f6f3011
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/5.1.1 CPython/3.12.7
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 8, 2024.
Transparency log