Skip to main content

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 embeddings
  • train.py: Training loop and logging logic
  • data.py: Basic character-level tokenization and dataset handling
  • utils.py: Configuration dataclasses and JSON loading
  • inference.py: Text generation utilities
  • distributed.py: Functions wrapping most of the distributed training related code
  • config/: 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mirrorshift-0.1.0.tar.gz (14.2 kB view details)

Uploaded Source

Built Distribution

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

mirrorshift-0.1.0-py3-none-any.whl (15.2 kB view details)

Uploaded Python 3

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

Hashes for mirrorshift-0.1.0.tar.gz
Algorithm Hash digest
SHA256 100991aabd8e129960ceef9d336f3fc0dcdef1c9780459a9787893dd022e0539
MD5 db02aff220f6c05ed62efcded9313946
BLAKE2b-256 984a24673a9005cf28d1790876af0b482299fe62b93aa8f4c2d5f37150dfd0a4

See more details on using hashes here.

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

Hashes for mirrorshift-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 112197c36b3eeedb061d7d504b2f16071caac2a8b39485eb7280acc7254726b1
MD5 7a1285fffae9bde957a9400d8db6d10d
BLAKE2b-256 ace041b075f95f41fd6e5c8c1cc1c8d78d3f6e9b70fcc3bfa785be896d29c6ec

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