Contributing
How to contribute to DREAM
Contributing
Thank you for your interest in contributing to DREAM! This guide covers how to contribute to the project.
Development Setup
Clone the Repository
git clone https://github.com/karl4th/dream-nn.git
cd dream-nnInstall Development Dependencies
pip install -e ".[dev]"This installs:
- DREAM in editable mode
- Testing frameworks (pytest)
- Code quality tools (black, flake8, mypy)
- Development dependencies
Verify Setup
# Run tests
pytest tests/
# Check code style
black --check dream/
flake8 dream/
# Type check
mypy dream/Pull Request Process
1. Fork the Repository
Click "Fork" on GitHub to create your own copy.
2. Create a Feature Branch
git checkout -b feature/your-feature-nameBranch naming conventions:
feature/- New featuresfix/- Bug fixesdocs/- Documentationrefactor/- Code refactoringtest/- Test additions
3. Make Changes
Follow the coding style:
- Use type hints
- Write docstrings
- Add tests for new features
- Keep functions small and focused
4. Add Tests
# Create test file
touch tests/test_your_feature.py
# Run tests
pytest tests/test_your_feature.py -v5. Run Code Quality Checks
# Format code
black dream/ tests/
# Lint
flake8 dream/ tests/
# Type check
mypy dream/ tests/6. Update Documentation
- Add docstrings to new functions/classes
- Update relevant documentation pages
- Add examples if applicable
7. Commit Changes
git add .
git commit -m "feat: add your feature description"Commit message conventions:
feat:- New featurefix:- Bug fixdocs:- Documentationstyle:- Code style changesrefactor:- Code refactoringtest:- Test additionschore:- Maintenance
8. Push and Create PR
git push origin feature/your-feature-nameThen create a Pull Request on GitHub.
Code Style
Formatting
We use Black for code formatting:
# Good
def process_sequence(
x: torch.Tensor,
hidden_dim: int = 256,
rank: int = 16,
) -> DREAMState:
"""Process sequence with DREAM."""
...Type Hints
Use type hints for all functions:
from typing import Tuple
import torch
from dream import DREAMState
def forward(
self,
x: torch.Tensor,
state: DREAMState | None = None,
) -> Tuple[torch.Tensor, DREAMState]:
"""Forward pass."""
...Docstrings
Use Google-style docstrings:
def init_state(
self,
batch_size: int,
device: str | None = None,
dtype: torch.dtype | None = None,
) -> DREAMState:
"""
Initialize cell state for a batch.
Args:
batch_size: Number of sequences in batch
device: Optional device (e.g., 'cuda', 'cpu')
dtype: Optional data type (e.g., torch.float32)
Returns:
DREAMState: Initialized state object
Example:
>>> state = cell.init_state(batch_size=32, device='cuda')
"""
...Naming Conventions
- Classes: PascalCase (
DREAMCell,DREAMState) - Functions: snake_case (
init_state,forward_sequence) - Constants: UPPER_CASE (
DEFAULT_RANK,MAX_TIME_STEP) - Private: leading underscore (
_internal_method)
Testing
Running Tests
# Run all tests
pytest tests/
# Run specific test file
pytest tests/test_dream.py
# Run with coverage
pytest tests/ --cov=dream
# Run specific test
pytest tests/test_dream.py::test_forward_pass -vWriting Tests
import torch
from dream import DREAM, DREAMConfig
def test_forward_pass():
"""Test basic forward pass."""
model = DREAM(input_dim=64, hidden_dim=128)
x = torch.randn(32, 50, 64)
output, state = model(x)
assert output.shape == (32, 50, 128)
assert state.h.shape == (32, 128)
def test_stateful_processing():
"""Test state preservation across sequences."""
model = DREAM(input_dim=64, hidden_dim=128)
state = model.init_state(batch_size=32)
x1 = torch.randn(32, 50, 64)
x2 = torch.randn(32, 50, 64)
output1, state1 = model(x1, state)
output2, state2 = model(x2, state1)
# State should be different after processing
assert not torch.allclose(state1.h, state2.h)Documentation
Writing Documentation
Documentation is in /content/docs/ as MDX files.
Structure:
- Use clear headings
- Include code examples
- Add tables for parameters
- Use notes and warnings
Example:
## Configuration
Set the learning rate:
```python
optimizer = torch.optim.AdamW(model.parameters(), lr=1e-3)Note: Learning rate can be adjusted during training using a scheduler.
### Building Documentation
```bash
# Run development server
npm run dev
# Build for production
npm run buildReporting Issues
Bug Reports
When reporting a bug, include:
- Description: Clear description of the issue
- Reproduction: Minimal code to reproduce
- Expected behavior: What should happen
- Actual behavior: What actually happens
- Environment:
- Python version
- PyTorch version
- DREAM version
- OS
Example:
### Bug Report
**Description:**
Loss becomes NaN during training.
**Reproduction:**
```python
model = DREAM(input_dim=64, hidden_dim=256)
# ... training codeExpected: Loss decreases normally Actual: Loss becomes NaN after 10 iterations
Environment:
- Python: 3.9
- PyTorch: 2.0.0
- DREAM: 0.1.2
- OS: Ubuntu 22.04
### Feature Requests
When requesting a feature, include:
1. **Problem**: What problem does this solve?
2. **Proposal**: How should it work?
3. **Alternatives**: What alternatives have you considered?
4. **Use case**: Example usage
---
## Code Review
### Review Checklist
Before submitting a PR, check:
- [ ] Code follows style guidelines
- [ ] Tests pass
- [ ] Documentation is updated
- [ ] Type hints are added
- [ ] Docstrings are complete
- [ ] No unnecessary changes
### Review Process
1. Maintainer reviews the code
2. Feedback is provided
3. Address feedback and push updates
4. PR is merged when approved
---
## Community Guidelines
### Be Respectful
- Be kind and respectful to others
- Use inclusive language
- Welcome different perspectives
### Be Constructive
- Provide constructive feedback
- Accept feedback gracefully
- Focus on the code, not the person
### Be Helpful
- Help other contributors
- Answer questions
- Share knowledge
---
## Questions?
If you have questions:
1. Check the [documentation](/docs)
2. Search existing [discussions](https://github.com/karl4th/dream-nn/discussions)
3. Start a new [discussion](https://github.com/karl4th/dream-nn/discussions)
---
## Next Steps
- [FAQ](/docs/faq) - Frequently asked questions
- [Troubleshooting](/docs/troubleshooting) - Common issues
- [Examples](/docs/examples) - Real-world examples