How hkproj/torchfeather works
Purpose and entry points
TorchFeather is a PyTorch distributed-training framework derived from TorchTitan, configured by default to train a DeepSeek-style MoE model. Cluster execution enters through launch.sh and trainer.slurm; Python training orchestration begins at torchfeather/train.py. Small parallelism demonstrations live under minimal_examples/.
Job configuration and assembly
torchfeather/config/job_config.py defines the training-job configuration surface, while torchfeather/config/default_configs.py supplies defaults. torchfeather/train.py consumes this configuration to construct the model, data pipeline, optimizer, scheduler, metrics, checkpointing, and distributed execution topology.
Model stack
The transformer implementation is centered in torchfeather/model/model.py, with model shape/options in torchfeather/model/model_args.py. Attention and rotary position encoding are isolated in torchfeather/model/attention.py and torchfeather/model/rope.py. torchfeather/model/parallelize.py is the model-to-distributed-runtime boundary, applying supported parallelization strategies to model modules.
Mixture-of-Experts path
MoE layers are implemented in torchfeather/model/moe/moe.py, with routing/dispatch support in torchfeather/model/moe/utils.py and specialized operations in torchfeather/model/moe/kernels.py. Expert execution integrates with distributed expert placement through torchfeather/distributed/expert_parallel.py; this is a key boundary between model-local routing and cross-rank communication.
Distributed execution topology
torchfeather/distributed/parallel_dims.py defines the multidimensional parallel layout. Runtime strategies include tensor/model parallelism in torchfeather/distributed/model_parallel.py, pipeline execution in torchfeather/distributed/pipeline_parallel.py, and activation rematerialization in torchfeather/distributed/activation_checkpoint.py. Shared process-group and rank utilities reside in torchfeather/distributed/utils.py. The trainer selects and composes these mechanisms rather than treating distribution as an external wrapper.
Training data and optimization flow
Training data is sourced through Hugging Face dataset integration in torchfeather/datasets/hf_datasets.py, then tokenized via torchfeather/components/tokenizer.py and batched by torchfeather/components/dataloader.py. Each training step in torchfeather/train.py flows through forward/loss, backward/distributed synchronization, optimizer update, and learning-rate scheduling. Those stages are encapsulated by torchfeather/components/loss.py, torchfeather/components/optimizer.py, and torchfeather/components/lr_scheduler.py.
State, observability, and infrastructure
Checkpoint save/load behavior is owned by torchfeather/components/checkpoint.py; metrics reporting is in torchfeather/components/metrics.py, with profiling/device support in torchfeather/tools/profiling.py and torchfeather/tools/device_utils.py. The intended infrastructure is a Slurm-managed multi-node GPU cluster (trainer.slurm, launch.sh). External dependencies include PyTorch distributed runtime, Hugging Face assets/datasets, and a DeepSeek-MoE tokenizer downloaded by scripts/download_hf_assets.py into the default-configured local assets path.
Main entry points: train.py Training orchestrator · parallelize.py Model parallelization · model.py DeepSeek MoE transformer · parallel_dims.py Parallel dimensions
Components 22
Cluster execution
- Launch scripts · Starts multi-node GPU training jobs.
launch.sh - Slurm job spec
trainer.slurm
Job assembly
- Training orchestrator · Assembles and runs the end-to-end training loop.
torchfeather/train.py - Job configuration
torchfeather/config/job_config.py - Default configuration
torchfeather/config/default_configs.py
Model and MoE
- Model arguments
torchfeather/model/model_args.py - DeepSeek MoE transformer
torchfeather/model/model.py - Attention and RoPE
torchfeather/model/attention.py - MoE layers and routing · Routes tokens to local expert computation.
torchfeather/model/moe/moe.py - Model parallelization · Applies selected distributed strategies to model modules.
torchfeather/model/parallelize.py
Distributed runtime
- Parallel dimensions · Defines the multidimensional parallel layout.
torchfeather/distributed/parallel_dims.py - Tensor/model parallelism
torchfeather/distributed/model_parallel.py - Pipeline execution
torchfeather/distributed/pipeline_parallel.py - Expert parallelism · Connects routed experts with distributed placement and communication.
torchfeather/distributed/expert_parallel.py
Data pipeline
- Hugging Face datasets
torchfeather/datasets/hf_datasets.py - Tokenizer
torchfeather/components/tokenizer.py - Data loader
torchfeather/components/dataloader.py
Training state
- Loss computation
torchfeather/components/loss.py - Optimizer
torchfeather/components/optimizer.py - Learning-rate scheduler
torchfeather/components/lr_scheduler.py - Checkpointing
torchfeather/components/checkpoint.py - Metrics and profiling
torchfeather/components/metrics.py
Connections 23
- Slurm job spec → Launch scripts: defines job
- Launch scripts → Training orchestrator: starts
- Default configuration → Job configuration: supplies defaults
- Job configuration → Training orchestrator: configures
- Training orchestrator → Model arguments: selects shape
- Model arguments → DeepSeek MoE transformer: parameterizes
- DeepSeek MoE transformer → Attention and RoPE: uses
- DeepSeek MoE transformer → MoE layers and routing: contains
- Training orchestrator → Model parallelization: applies strategies
- Model parallelization → DeepSeek MoE transformer: transforms modules
- Parallel dimensions → Model parallelization: drives layout
- Model parallelization → Tensor/model parallelism: enables
- Model parallelization → Pipeline execution: enables
- MoE layers and routing → Expert parallelism: dispatches experts
- Parallel dimensions → Expert parallelism: places experts
- Hugging Face datasets → Tokenizer: provides samples
- Tokenizer → Data loader: produces tokens
- Data loader → Training orchestrator: feeds batches
- Training orchestrator → Loss computation: computes loss
- Loss computation → Optimizer: backpropagates gradients
- Optimizer → Learning-rate scheduler: updates with schedule
- Training orchestrator → Checkpointing: saves and restores state
- Training orchestrator → Metrics and profiling: reports progress