my personal repo for transformers implementations and experiments
Project description
mirrorshift
personal repo for transformers code
- probably not well-organized or optimized, but getting there
Contents
models.py: Transformer implementations with GQA and MLA attention mechanisms, RoPE embeddingstrain.py: Training loop and logging logicdata.py: Basic character-level tokenization and dataset handlingutils.py: Configuration dataclasses and JSON loadinginference.py: Text generation utilitiesdistributed.py: Functions wrapping most of the distributed training related codeconfig/: JSON files for model architecture and training parameters
Installation
Development Installation
Clone the repository and install it in development mode:
git clone https://github.com/sapiosaturn/mirrorshift.git
cd mirrorshift
pip install -e .
This will install the package in development mode, allowing you to make changes to the code.
Using UV (Alternative)
If you prefer using UV package manager:
git clone https://github.com/sapiosaturn/mirrorshift.git
cd mirrorshift
uv sync && source .venv/bin/activate
Usage
Running as a Package
After installation, you can train a model using:
mirrorshift-train --model-config mirrorshift/config/model_configs/small.json \
--training-config mirrorshift/config/training_configs/small.json \
--dataset mirrorshift/datasets/coqa_stories.txt
Running from the Repository
If you didn't install as a package, you can run directly with Python:
python -m mirrorshift.train --model-config mirrorshift/config/model_configs/small.json \
--training-config mirrorshift/config/training_configs/small.json \
--dataset mirrorshift/datasets/coqa_stories.txt
Distributed Training
To run on multiple GPUs:
torchrun --nproc_per_node=<number of GPUs> -m mirrorshift.train
with any additional arguments as needed.
Visualization
Visualize training with tensorboard (loss curves and text samples are saved):
tensorboard --logdir runs/
Using in Your Python Code
You can also use the components directly in your Python code:
from mirrorshift import CausalTransformer, ModelConfig
# Create a model config
config = ModelConfig(
vocab_size=50000,
num_layers=12,
embedding_dim=768,
num_heads=12,
num_kv_heads=4,
context_length=1024,
feedforward_dim=3072,
attention_dropout_p=0.1,
residual_dropout_p=0.1,
attention_type="gqa"
)
# Initialize a model
model = CausalTransformer(model_config=config)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mirrorshift-0.1.0.tar.gz.
File metadata
- Download URL: mirrorshift-0.1.0.tar.gz
- Upload date:
- Size: 14.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
100991aabd8e129960ceef9d336f3fc0dcdef1c9780459a9787893dd022e0539
|
|
| MD5 |
db02aff220f6c05ed62efcded9313946
|
|
| BLAKE2b-256 |
984a24673a9005cf28d1790876af0b482299fe62b93aa8f4c2d5f37150dfd0a4
|
File details
Details for the file mirrorshift-0.1.0-py3-none-any.whl.
File metadata
- Download URL: mirrorshift-0.1.0-py3-none-any.whl
- Upload date:
- Size: 15.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
112197c36b3eeedb061d7d504b2f16071caac2a8b39485eb7280acc7254726b1
|
|
| MD5 |
7a1285fffae9bde957a9400d8db6d10d
|
|
| BLAKE2b-256 |
ace041b075f95f41fd6e5c8c1cc1c8d78d3f6e9b70fcc3bfa785be896d29c6ec
|