Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Open more actions menu

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

106 Commits
106 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Translating Meaning - Machine Translation Project

A machine translation project exploring fine-tuning transformer models for translation tasks, with comprehensive documentation and cross-platform support.

Quick Start

Installation

# Create virtual environment
python3 -m venv .venv
source .venv/bin/activate

# Install dependencies
pip install -r requirements.txt

# Install Jupyter kernel for notebook execution
python -m ipykernel install --user --name=translation --display-name="translation"

Training

# Activate environment
source .venv/bin/activate

# Run training with papermill
./train_with_papermill.sh --epochs 3 --num-samples 1000

# Or with custom parameters
./train_with_papermill.sh --epochs 5 --lr 1e-4 --num-samples 5000

PyTorch Version Requirements

macOS Users

The project uses PyTorch 2.3.1 by default, which supports MPS (Metal Performance Shaders) on macOS 12.3+ (Monterey).

To use newer PyTorch versions on macOS:

Your macOS Version Recommended PyTorch How to Upgrade
12.3 - 12.7 (Monterey) 2.3.1 (default) ✅ Already optimal
13.0+ (Ventura or newer) 2.8.0+ (latest) See instructions below

Upgrade to latest PyTorch (macOS 13+ only):

pip install --upgrade torch torchvision torchaudio

Non-macOS Users (Linux, Windows, Google Colab)

You can use the latest PyTorch without restrictions:

# Unpin PyTorch in requirements.txt, then:
pip install --upgrade torch torchvision torchaudio

Or edit requirements.txt to use:

torch>=2.8.0  # Latest version
torchvision
torchaudio

Why is PyTorch Pinned?

PyTorch 2.5+ requires macOS 13.0+ for MPS (GPU acceleration). Since this project was developed on macOS 12.7.6, we pin to 2.3.1 to ensure MPS works. If you have newer macOS or aren't using MPS, feel free to upgrade!

Hardware Acceleration

Apple Silicon (M1/M2/M3)

  • macOS 12.3-12.7: Uses MPS with PyTorch 2.3.1 (~3-5x faster than CPU)
  • macOS 13.0+: Can use MPS with PyTorch 2.8+ (~3-5x faster than CPU)
  • Older macOS: Falls back to CPU

NVIDIA GPUs

  • Uses CUDA automatically with any PyTorch version
  • Significantly faster than CPU or MPS

CPU Only

  • Works on all platforms
  • Slower but functional for development/testing

Project Structure

.
├── translating_with_gemma.ipynb  # Main training notebook
├── train_with_papermill.sh       # Automated training script
├── requirements.txt              # Python dependencies
├── article.md                    # Technical article
├── diagrams/                     # Mermaid diagrams

Documentation

  • article.md - Complete technical article on machine translation with Gemma 3
  • TRAINING.md - Training guide and configuration reference
  • MODEL_CHECKPOINT.md - Model checkpoint management and HuggingFace Hub upload
  • CLAUDE.md - Development guide and project architecture

Features

Cross-Platform Support

  • ✅ CUDA (NVIDIA GPUs) - Automatic quantization
  • ✅ MPS (Apple Silicon) - Native acceleration
  • ✅ CPU - Universal fallback

Smart Package Installation

  • Skips pip installs when running via papermill (faster)
  • Runs installs normally in Jupyter/Colab (full compatibility)
  • Uses custom %%skip_if_env magic command

Reproducible Training

  • Papermill-based execution with parameters
  • Timestamped output notebooks
  • TensorBoard logging

Environment Management

  • Handles pyenv/venv conflicts automatically
  • Correct Jupyter kernel selection
  • Explicit binary paths to avoid issues

Training Options

./train_with_papermill.sh [options]

Options:
  --epochs N              Number of training epochs (default: 3)
  --lr RATE              Learning rate (default: 2e-4)
  --num-samples N        Training samples (default: 1000)
  --lora-r N             LoRA rank (default: 16)
  --lora-alpha N         LoRA alpha (default: 32)
  --skip-install         Skip pip installs (default: true)
  --no-skip-install      Run pip installs

Troubleshooting

MPS Not Available on macOS

See MPS_TROUBLESHOOTING.md for:

  • PyTorch version compatibility matrix
  • Diagnostic commands
  • Step-by-step solutions

Package Import Errors

# Verify all packages
python -c "import torch, transformers, datasets, peft; print('OK')"

# Reinstall if needed
pip install -r requirements.txt

Pyenv/Venv Conflicts

See PYENV_VENV_TROUBLESHOOTING.md

Performance Expectations

Hardware Training Speed Recommended Use
CUDA GPU (A100) Fastest Production training
CUDA GPU (T4) Very Fast Development/Testing
Apple Silicon (MPS) 3-5x CPU Local development
CPU Baseline Quick tests only

Contributing

This is a research/learning project. Feel free to adapt for your own use!

License

See LICENSE file for details.

Related Files

  • Article: article.md - Technical writeup on machine translation
  • Training Logs: training_runs/ - Executed notebooks with results
  • Models: Models saved to specified output directory
  • Diagrams: diagrams/ - Visual explanations of concepts

About

Article and sample code on neural machine translation using pytorch

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages

Morty Proxy This is a proxified and sanitized view of the page, visit original site.