-
Notifications
You must be signed in to change notification settings - Fork 16
Add basic API docs #336
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Add basic API docs #336
Changes from 26 commits
Commits
Show all changes
34 commits
Select commit
Hold shift + click to select a range
d3f729f
Update
svekars 9823f1f
Update
svekars e9bd538
Add API docs for actor/service
svekars 23dda07
Update
svekars 76434e3
Update
svekars d9542a3
Update
svekars f101a80
Update
svekars 067ded4
Update
svekars 499c919
Update
svekars ef35244
precommit
svekars bbd8d8f
Fixes
svekars cba68df
Update
svekars f828bc1
Update
svekars 60ec7e7
Precommit
svekars 754f7f7
Update
svekars cf66872
Update
svekars b7b39c1
Update
svekars dfb2b01
Update
svekars 678c82c
Update
svekars 8162490
Update
svekars 5d1c5c9
Update
svekars 197d24d
Update
svekars bb6b585
Update
svekars 8c186b1
Update
svekars 25221e7
Update
svekars f3c79f6
Update
svekars bee92c6
Update docs/source/api.md
svekars ae05ebf
Update
svekars 0060494
Update
svekars 16c89c1
Merge branch 'main' into api-docs
svekars 00842a5
Update
svekars 635bbc1
Update
svekars a1972f5
Update
svekars efc74c6
Fix example line
svekars File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
/* Custom CSS for collapsible parameter lists */ | ||
|
||
/* Hide parameters in signatures */ | ||
.sig-param-hidden { | ||
display: none !important; | ||
} | ||
|
||
/* Inline toggle button for signatures */ | ||
.params-toggle-btn-inline { | ||
display: inline; | ||
padding: 0.2rem 0.5rem; | ||
margin: 0 0.25rem; | ||
background-color: var(--pst-color-background); | ||
border: 1px solid var(--pst-color-border); | ||
border-radius: 3px; | ||
cursor: pointer; | ||
font-size: 0.85em; | ||
font-family: var(--pst-font-family-base); | ||
color: var(--pst-color-primary); | ||
transition: all 0.2s ease; | ||
vertical-align: middle; | ||
} | ||
|
||
.params-toggle-btn-inline:hover { | ||
background-color: var(--pst-color-background); | ||
border-color: var(--pst-color-border); | ||
} | ||
|
||
.params-toggle-btn-inline:focus { | ||
outline: none; | ||
} | ||
|
||
.toggle-icon { | ||
display: inline-block; | ||
font-size: 0.8em; | ||
transition: transform 0.2s ease; | ||
} | ||
|
||
/* Wrapper for the button */ | ||
.sig-params-wrapper { | ||
display: inline; | ||
} | ||
|
||
/* Old styles for field-list collapsing (kept for backward compatibility) */ | ||
.collapsible-params { | ||
margin: 1rem 0; | ||
} | ||
|
||
.params-toggle-btn { | ||
display: inline-block; | ||
padding: 0.5rem 1rem; | ||
margin-bottom: 0.5rem; | ||
background-color: var(--pst-color-background); | ||
border: 1px solid var(--pst-color-border); | ||
border-radius: 4px; | ||
cursor: pointer; | ||
font-size: 0.9rem; | ||
color: var(--pst-color-primary); | ||
transition: all 0.3s ease; | ||
} | ||
|
||
.params-toggle-btn:hover { | ||
background-color: var(--pst-color-background); | ||
border-color: var(--pst-color-border); | ||
} | ||
|
||
.params-content { | ||
max-height: 10000px; | ||
overflow: hidden; | ||
transition: max-height 0.5s ease, opacity 0.3s ease; | ||
opacity: 1; | ||
} | ||
|
||
.params-content.collapsed { | ||
max-height: 0; | ||
opacity: 0; | ||
} | ||
|
||
/* Ensure the collapsed parameters look good */ | ||
.params-content dl.field-list { | ||
margin-top: 0; | ||
} | ||
|
||
.params-content > dt { | ||
margin-top: 0.5rem; | ||
} | ||
|
||
.params-content > dt:first-child { | ||
margin-top: 0; | ||
} | ||
|
||
/* Responsive adjustments */ | ||
@media (max-width: 768px) { | ||
.params-toggle-btn { | ||
width: 100%; | ||
text-align: left; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
// Custom JavaScript to make long parameter lists in class signatures collapsible | ||
document.addEventListener('DOMContentLoaded', function() { | ||
console.log('Collapsible parameters script loaded'); | ||
|
||
// Find all class/function signatures | ||
const signatures = document.querySelectorAll('dl.py.class > dt, dl.py.function > dt, dl.py.method > dt'); | ||
|
||
signatures.forEach(function(signature) { | ||
// Find all parameter elements in the signature | ||
const params = signature.querySelectorAll('em.sig-param, .sig-param'); | ||
|
||
console.log(`Found signature with ${params.length} parameters`); | ||
|
||
// Only make it collapsible if there are more than 10 parameters | ||
if (params.length > 10) { | ||
console.log('Creating collapsible structure for signature with', params.length, 'parameters'); | ||
|
||
const visibleCount = 5; | ||
const hiddenCount = params.length - visibleCount; | ||
|
||
// Create a wrapper div for the toggle button | ||
const wrapper = document.createElement('span'); | ||
wrapper.className = 'sig-params-wrapper'; | ||
wrapper.style.display = 'inline'; | ||
|
||
// Create toggle button | ||
const toggleBtn = document.createElement('button'); | ||
toggleBtn.className = 'params-toggle-btn-inline'; | ||
toggleBtn.innerHTML = `<i class="fa-solid fa-chevron-right"></i> Show More`; | ||
toggleBtn.setAttribute('aria-expanded', 'false'); | ||
toggleBtn.title = `Show ${hiddenCount} more parameters`; | ||
|
||
// Collect all nodes to hide (params and text nodes between them) | ||
const nodesToHide = []; | ||
|
||
// Hide parameters after the first 3 | ||
let insertedButton = false; | ||
params.forEach(function(param, index) { | ||
if (index >= visibleCount) { | ||
// Add 'hidden' class to hide the parameter | ||
param.classList.add('sig-param-hidden'); | ||
nodesToHide.push(param); | ||
|
||
// Also hide the text node (comma/space) that follows this parameter | ||
let nextNode = param.nextSibling; | ||
while (nextNode && nextNode.nodeType === Node.TEXT_NODE) { | ||
const textSpan = document.createElement('span'); | ||
textSpan.className = 'sig-param-hidden'; | ||
textSpan.textContent = nextNode.textContent; | ||
nextNode.parentNode.replaceChild(textSpan, nextNode); | ||
nodesToHide.push(textSpan); | ||
break; | ||
} | ||
|
||
// Insert the toggle button before the first hidden parameter | ||
if (!insertedButton) { | ||
param.parentNode.insertBefore(wrapper, param); | ||
wrapper.appendChild(toggleBtn); | ||
insertedButton = true; | ||
} | ||
} | ||
}); | ||
|
||
// Add click handler to toggle | ||
toggleBtn.addEventListener('click', function(e) { | ||
e.preventDefault(); | ||
e.stopPropagation(); | ||
|
||
const isExpanded = toggleBtn.getAttribute('aria-expanded') === 'true'; | ||
|
||
if (isExpanded) { | ||
// Collapse: hide parameters again | ||
nodesToHide.forEach(function(node) { | ||
node.classList.add('sig-param-hidden'); | ||
}); | ||
toggleBtn.setAttribute('aria-expanded', 'false'); | ||
toggleBtn.innerHTML = `<i class="fa-solid fa-chevron-right"></i> Show More`; | ||
toggleBtn.title = `Show ${hiddenCount} more parameters`; | ||
} else { | ||
// Expand: show all parameters | ||
nodesToHide.forEach(function(node) { | ||
node.classList.remove('sig-param-hidden'); | ||
}); | ||
toggleBtn.setAttribute('aria-expanded', 'true'); | ||
toggleBtn.innerHTML = `<i class="fa-solid fa-chevron-down"></i> Hide`; | ||
toggleBtn.title = `Hide ${hiddenCount} parameters`; | ||
} | ||
}); | ||
|
||
console.log('Collapsible structure created successfully'); | ||
} | ||
}); | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,35 @@ | ||
# API Reference | ||
|
||
This section provides comprehensive API documentation for TorchForge modules and classes. | ||
This section provides comprehensive API documentation for TorchForge. | ||
|
||
TorchForge is organized into several key modules, each providing specialized functionality for post-training generative AI models: | ||
## Overview | ||
|
||
## Module Overview | ||
TorchForge is a PyTorch native platform for post-training generative AI models, | ||
designed to streamline reinforcement learning workflows for large language | ||
models. The platform leverages PyTorch's distributed computing capabilities | ||
and is built on top of [Monarch](https://meta-pytorch.org/monarch/), | ||
making extensive use of actors for distributed computation and fault tolerance. | ||
|
||
**Core Components** | ||
- [Interfaces & Types](api_core.md) - Core interfaces and type definitions | ||
- [Actors](api_actors.md) - Model training and inference components | ||
- [Controller](api_controller.md) - Distributed training orchestration and resource management | ||
Key Features of TorchForge include: | ||
|
||
**Data Management** | ||
- [Data](api_data.md) - Data handling utilities, datasets, and data models | ||
- **Actor-Based Architecture**: TorchForge uses an actor-based system for distributed training, providing excellent scalability and fault tolerance. | ||
- **PyTorch Native**: Built natively on PyTorch, ensuring seamless integration with existing PyTorch workflows. | ||
- **Post-Training Focus**: Specifically designed for post-training techniques like RLHF, SFT, and other alignment methods. | ||
- **Distributed by Design**: Supports multi-GPU and multi-node training out of the box. | ||
|
||
**Training Components** | ||
- [Losses](api_losses.md) - Loss functions for reinforcement learning and supervised fine-tuning | ||
- [Environments](api_envs.md) - Training and inference environments | ||
|
||
**Tools & Utilities** | ||
- [Utilities](api_util.md) - General utility functions and helpers | ||
For most use cases, you'll interact with the high-level service | ||
interfaces, which handle the complexity of actor coordination and | ||
distributed training automatically. | ||
|
||
```{toctree} | ||
:maxdepth: 2 | ||
:hidden: | ||
For advanced users who need fine-grained control, the individual actor | ||
APIs provide direct access to the underlying distributed components. | ||
|
||
api_core | ||
```{toctree} | ||
:maxdepth: 1 | ||
api_actors | ||
api_data | ||
api_losses | ||
api_envs | ||
api_controller | ||
api_util | ||
api_service | ||
api_generator | ||
api_model | ||
api_trainer | ||
``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,20 @@ | ||
# Actors | ||
|
||
The actors module contains the core components for model training and inference in TorchForge. This includes policy actors, reference models, replay buffers, and trainers. | ||
|
||
## Policy Actor | ||
|
||
The policy actor is responsible for model inference and policy interactions during training. | ||
|
||
## Reference Model | ||
|
||
The reference model provides baseline comparisons for reinforcement learning algorithms. | ||
|
||
## Replay Buffer | ||
|
||
The replay buffer manages storage and sampling of training experiences. | ||
|
||
## Trainer | ||
|
||
The trainer orchestrates the training process and implements training algorithms. | ||
# ForgeActor | ||
|
||
```{eval-rst} | ||
.. currentmodule:: forge.actors | ||
``` | ||
|
||
The actors module contains the core components for model training | ||
and inference in TorchForge. These pre-built actors provide essential | ||
functionality for reinforcement learning workflows and can be used | ||
as building blocks for complex distributed training systems. | ||
|
||
```{eval-rst} | ||
.. currentmodule:: forge.controller.actor | ||
|
||
.. autoclass:: ForgeActor | ||
:members: | ||
:undoc-members: | ||
:show-inheritance: | ||
:exclude-members: logger, setup, set_env, __init__ | ||
``` |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.