Thank you for your interest in contributing to LuminaAI! This document provides guidelines for contributing to the project.
- Getting Started
- Development Setup
- How to Contribute
- Code Standards
- Testing Guidelines
- Pull Request Process
- Areas for Contribution
- Community
- Python 3.8+
- PyTorch 2.0+
- Git
- Understanding of transformer architectures (recommended)
- Experience with deep learning training (helpful)
-
Read the Documentation
- Review the README thoroughly
- Understand the adaptive training system
- Familiarize yourself with MoE/MoD architectures
-
Set Up Your Environment
- Fork the repository
- Clone your fork locally
- Install dependencies (see Development Setup)
-
Explore the Codebase
- Run the
debugconfiguration to understand the system - Review existing code in
Src/directory - Read inline documentation and comments
- Run the
# Clone your fork
git clone https://github.com/YOUR_USERNAME/luminaai.git
cd luminaai
# Create virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install dependencies
pip install -r requirements.txt
# Install development dependencies
pip install -r requirements-dev.txt # If available
# Install pre-commit hooks (if configured)
pre-commit install# Run all tests
pytest tests/
# Run specific test file
pytest tests/test_trainer.py
# Run with coverage
pytest --cov=Src tests/
# Run debug configuration (quick validation)
cd Src/Main_Scripts
python Main.py # Should complete in ~5 minutes# Format code
black Src/
# Lint code
flake8 Src/
pylint Src/
# Type checking
mypy Src/
# Sort imports
isort Src/We welcome various types of contributions:
- Bug Fixes: Fix training instabilities, crashes, or incorrect behavior
- Features: Add new architectures, optimizers, or training techniques
- Performance: Optimize throughput, memory usage, or convergence
- Documentation: Improve guides, docstrings, or examples
- Tests: Add test coverage for untested components
- Research: Implement papers or experimental techniques
- Check the Issues page
- Look for labels:
good first issue: Great for newcomershelp wanted: Maintainers need assistancebug: Known issues needing fixesenhancement: New features or improvementsdocumentation: Docs improvementsperformance: Optimization opportunities
- Check for existing work: Search issues and PRs to avoid duplication
- Discuss major changes: Open an issue first for significant features
- Assign yourself: Comment on the issue to claim it
- Ask questions: Reach out if you need clarification
- Python Style: Follow PEP 8
- Line Length: Maximum 88 characters (Black default)
- Imports: Use
isortfor consistent import ordering - Naming Conventions:
- Classes:
PascalCase - Functions/methods:
snake_case - Constants:
UPPER_SNAKE_CASE - Private methods:
_leading_underscore
- Classes:
Use Google-style docstrings:
def adjust_capacity_factor(self, new_factor: float) -> None:
"""Dynamically adjust MoE capacity factor during training.
This method modifies how many tokens can be routed to each expert,
affecting load balancing and training stability.
Args:
new_factor: New capacity factor (typically 1.0-2.0).
Higher values allow more tokens per expert but increase
memory usage. Lower values improve efficiency but may
cause token dropping.
Raises:
ValueError: If new_factor <= 0.
Example:
>>> trainer.adjust_capacity_factor(1.5)
>>> # Allows 50% more tokens per expert
Note:
Changes take effect on the next forward pass. This is safe
to call during training.
"""
if new_factor <= 0:
raise ValueError(f"Capacity factor must be positive, got {new_factor}")
self.config.capacity_factor = new_factor
self.logger.info(f"Adjusted capacity factor to {new_factor}")- Why over what: Explain reasoning, not obvious operations
- Complex logic: Add comments for non-trivial algorithms
- TODOs: Include TODOs with issue numbers when applicable
# Good: Explains why
# Use emergency LR reduction to prevent gradient explosion
# rather than simple clipping, which masks the underlying issue
self.emergency_lr_reduction(factor=10.0)
# Bad: States the obvious
# Reduce learning rate
self.learning_rate *= 0.1Follow these design principles from the codebase:
- Autonomy: Systems should self-optimize when possible
- Observability: Expose metrics for monitoring and debugging
- Recovery: Handle failures gracefully with automatic recovery
- Flexibility: Support multiple architectures and configurations
- Production-Ready: Include error handling, logging, and checkpointing
tests/
unit/ # Unit tests for individual components
test_trainer.py
test_model.py
test_config.py
integration/ # Integration tests for workflows
test_training_loop.py
test_checkpointing.py
fixtures/ # Shared test data and fixtures
sample_configs.py
import pytest
import torch
from src.trainer import Trainer
class TestTrainer:
@pytest.fixture
def trainer(self):
"""Create a minimal trainer for testing."""
config = Config(
hidden_size=128,
num_layers=2,
num_heads=4,
vocab_size=1000
)
return Trainer(config)
def test_adjust_capacity_factor(self, trainer):
"""Test capacity factor adjustment."""
original = trainer.config.capacity_factor
trainer.adjust_capacity_factor(2.0)
assert trainer.config.capacity_factor == 2.0
assert trainer.config.capacity_factor != original
def test_adjust_capacity_factor_invalid(self, trainer):
"""Test capacity factor validation."""
with pytest.raises(ValueError):
trainer.adjust_capacity_factor(-1.0)
@pytest.mark.skipif(not torch.cuda.is_available(), reason="CUDA required")
def test_training_on_gpu(self, trainer):
"""Test training stability on GPU."""
# Implementation
pass- Minimum coverage: Aim for 80% coverage on new code
- Critical paths: 100% coverage for training loop, checkpointing, recovery
- Edge cases: Test boundary conditions and error paths
- Hardware: Mark hardware-specific tests with appropriate decorators
For optimization PRs, include benchmarks:
def test_flash_attention_speedup():
"""Verify Flash Attention improves throughput."""
baseline_throughput = benchmark_without_flash_attention()
optimized_throughput = benchmark_with_flash_attention()
assert optimized_throughput > baseline_throughput * 1.5 # At least 1.5x faster# Create a feature branch
git checkout -b feature/add-moe-pruning
# Make your changes
# ...
# Commit with clear messages
git add .
git commit -m "feat: Add dynamic MoE expert pruning
- Implement automatic expert removal based on utilization
- Add pruning threshold configuration option
- Include tests for pruning logic
- Update documentation with pruning examples
Fixes #123"Follow Conventional Commits:
<type>(<scope>): <subject>
<body>
<footer>
Types:
feat: New featurefix: Bug fixdocs: Documentation changesperf: Performance improvementrefactor: Code refactoringtest: Adding/updating testschore: Maintenance tasks
Examples:
feat(moe): Add dynamic expert pruning
Implements automatic removal of underutilized experts during training
to improve efficiency and reduce memory usage.
Fixes #123
perf(attention): Optimize Flash Attention memory usage
Reduce peak memory consumption by 25% through better kernel fusion.
Benchmark results:
- A100 40GB: 1200 tok/s 1500 tok/s
- Memory: 32GB 24GB
- Run all tests:
pytest tests/ - Check code style:
black Src/ && flake8 Src/ - Update documentation if needed
- Add tests for new functionality
- Ensure CI passes locally
- Rebase on latest
mainbranch
# Update your branch
git fetch upstream
git rebase upstream/main
# Run final checks
pytest tests/
black Src/
flake8 Src/-
Push to your fork:
git push origin feature/add-moe-pruning
-
Open PR on GitHub using the Pull Request template
-
Fill out all sections thoroughly
-
Link related issues (e.g., "Fixes #123")
- Automated checks: CI must pass (tests, linting, etc.)
- Code review: At least one maintainer approval required
- Feedback: Address reviewer comments promptly
- Updates: Push additional commits to same branch
- Merge: Maintainer will merge once approved
- Initial review: Within 3-5 days
- Follow-up reviews: Within 2-3 days
- Complex PRs may take longer
-
Training Stability
- Improve gradient explosion detection
- Add more sophisticated recovery mechanisms
- Implement better loss spike handling
-
Performance Optimization
- Flash Attention improvements
- Better memory management
- Faster data loading
-
Architecture Support
- Additional sparse architectures
- Quantization-aware training
- Distillation support
-
Testing
- Multi-GPU test coverage
- Edge case testing
- Integration test suite
-
Documentation
- Tutorial notebooks
- Architecture deep-dives
- Troubleshooting guides
-
Monitoring
- Improved metrics dashboard
- Better visualization
- Real-time alerts
-
Data Pipeline
- More efficient data loading
- Better preprocessing
- Dataset utilities
Implementing recent papers:
- New attention mechanisms
- Advanced MoE routing strategies
- Novel optimization techniques
- Improved scaling laws
Requirements for research PRs:
- Cite original paper
- Provide ablation studies
- Include reproducible configs
- Document limitations
- GitHub Issues: Bug reports and feature requests
- GitHub Discussions: General questions and ideas
- Pull Requests: Code contributions and reviews
- Check documentation
- Search existing issues
- Ask in Discussions
- Tag maintainers for urgent issues
Contributors are recognized in:
- README.md contributors section
- Release notes for significant contributions
- Special thanks for major features
By contributing, you agree that your contributions will be licensed under the same license as the project (see LICENSE).
If you have questions about contributing, please:
- Check this guide thoroughly
- Search existing issues and discussions
- Open a new issue with the
questionlabel
Thank you for contributing to LuminaAI!
We're building the future of autonomous training systems together.