Skip to content

Commit 39aa0cb

Browse files
svekarscasteryh
andauthored
Address diagram issues in the tutorials (#445)
Co-authored-by: casteryh <[email protected]>
1 parent 8919815 commit 39aa0cb

File tree

7 files changed

+347
-72
lines changed

7 files changed

+347
-72
lines changed

docs/source/_static/custom.css

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,62 @@
1+
/* Center all Mermaid diagrams */
2+
.mermaid {
3+
display: block;
4+
margin-left: auto;
5+
margin-right: auto;
6+
text-align: center;
7+
}
8+
9+
/* Center the pre element that contains mermaid diagrams */
10+
pre.mermaid {
11+
display: flex;
12+
justify-content: center;
13+
}
14+
15+
/* Adjust Mermaid line colors based on theme */
16+
/* Light mode - darker lines for visibility on white background */
17+
html[data-theme="light"] .mermaid .edgePath .path,
18+
html[data-theme="light"] .mermaid .flowchart-link {
19+
stroke: #555 !important;
20+
stroke-width: 2px !important;
21+
}
22+
23+
/* Light mode - darker arrow tips */
24+
html[data-theme="light"] .mermaid .arrowheadPath,
25+
html[data-theme="light"] .mermaid marker path {
26+
fill: #555 !important;
27+
stroke: #555 !important;
28+
}
29+
30+
html[data-theme="dark"] .mermaid .arrowheadPath,
31+
html[data-theme="dark"] .mermaid marker path {
32+
fill: #aaa !important;
33+
stroke: #aaa !important;
34+
}
35+
36+
/* Dark mode - lighter lines for visibility on dark background */
37+
html[data-theme="dark"] .mermaid .edgePath .path,
38+
html[data-theme="dark"] .mermaid .flowchart-link {
39+
stroke: #aaa !important;
40+
stroke-width: 2px !important;
41+
}
42+
43+
/* Dark mode - lighter arrow tips */
44+
html[data-theme="dark"] .mermaid .arrowheadPath,
45+
html[data-theme="dark"] .mermaid marker path {
46+
fill: #aaa !important;
47+
stroke: #aaa !important;
48+
}
49+
50+
/* Adjust edge labels background based on theme */
51+
html[data-theme="light"] .mermaid .edgeLabel {
52+
background-color: #fff !important;
53+
}
54+
55+
html[data-theme="dark"] .mermaid .edgeLabel {
56+
background-color: #1a1a1a !important;
57+
color: #fff !important;
58+
}
59+
160
/* Custom CSS for collapsible parameter lists */
261

362
/* Hide parameters in signatures */

docs/source/_static/custom.js

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,103 @@
1+
// Lightbox functionality for Mermaid diagrams
2+
document.addEventListener('DOMContentLoaded', function() {
3+
// Create lightbox modal for Mermaid diagrams
4+
const lightbox = document.createElement('div');
5+
lightbox.id = 'mermaid-lightbox';
6+
lightbox.style.cssText = `
7+
display: none;
8+
position: fixed;
9+
z-index: 9999;
10+
left: 0;
11+
top: 0;
12+
width: 100%;
13+
height: 100%;
14+
background-color: rgba(0,0,0,0.9);
15+
cursor: zoom-out;
16+
`;
17+
18+
const lightboxContent = document.createElement('div');
19+
lightboxContent.style.cssText = `
20+
position: absolute;
21+
top: 50%;
22+
left: 50%;
23+
transform: translate(-50%, -50%);
24+
max-width: 95%;
25+
max-height: 95%;
26+
overflow: auto;
27+
`;
28+
29+
const closeBtn = document.createElement('span');
30+
closeBtn.innerHTML = '&times;';
31+
closeBtn.style.cssText = `
32+
position: absolute;
33+
top: 15px;
34+
right: 35px;
35+
color: #f1f1f1;
36+
font-size: 40px;
37+
font-weight: bold;
38+
cursor: pointer;
39+
z-index: 10000;
40+
`;
41+
closeBtn.onclick = function() {
42+
lightbox.style.display = 'none';
43+
};
44+
45+
lightbox.appendChild(closeBtn);
46+
lightbox.appendChild(lightboxContent);
47+
document.body.appendChild(lightbox);
48+
49+
// Click outside to close
50+
lightbox.onclick = function(e) {
51+
if (e.target === lightbox) {
52+
lightbox.style.display = 'none';
53+
}
54+
};
55+
56+
// ESC key to close
57+
document.addEventListener('keydown', function(e) {
58+
if (e.key === 'Escape' && lightbox.style.display === 'block') {
59+
lightbox.style.display = 'none';
60+
}
61+
});
62+
63+
// Make all Mermaid diagrams clickable
64+
const mermaidDivs = document.querySelectorAll('.mermaid');
65+
mermaidDivs.forEach(function(div) {
66+
div.style.cursor = 'zoom-in';
67+
div.title = 'Click to enlarge';
68+
69+
div.addEventListener('click', function() {
70+
const clone = div.cloneNode(true);
71+
72+
// Style the cloned diagram to fill the lightbox
73+
clone.style.cssText = `
74+
cursor: default;
75+
width: 90vw;
76+
max-width: 1400px;
77+
height: auto;
78+
margin: auto;
79+
`;
80+
81+
// Find and resize the SVG inside
82+
const svg = clone.querySelector('svg');
83+
if (svg) {
84+
svg.style.cssText = `
85+
width: 100% !important;
86+
height: auto !important;
87+
max-width: none !important;
88+
max-height: 90vh !important;
89+
`;
90+
svg.removeAttribute('width');
91+
svg.removeAttribute('height');
92+
}
93+
94+
lightboxContent.innerHTML = '';
95+
lightboxContent.appendChild(clone);
96+
lightbox.style.display = 'block';
97+
});
98+
});
99+
});
100+
1101
// Custom JavaScript to make long parameter lists in class signatures collapsible
2102
document.addEventListener('DOMContentLoaded', function() {
3103
console.log('Collapsible parameters script loaded');

docs/source/conf.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,30 @@ def get_version_path():
178178
# Configure MyST parser to treat mermaid code blocks as mermaid directives
179179
myst_fence_as_directive = ["mermaid"]
180180

181+
# Disable D3 zoom (we'll use lightbox instead)
182+
mermaid_d3_zoom = False
183+
184+
# Global Mermaid theme configuration - applies to all diagrams
185+
mermaid_init_js = """
186+
import mermaid from 'https://cdn.jsdelivr.net/npm/[email protected]/dist/mermaid.esm.min.mjs';
187+
mermaid.initialize({
188+
startOnLoad: false,
189+
theme: 'base',
190+
themeVariables: {
191+
primaryColor: '#4CAF50',
192+
primaryTextColor: '#000',
193+
primaryBorderColor: '#fff',
194+
lineColor: '#555',
195+
secondaryColor: '#FF9800',
196+
tertiaryColor: '#ffffde'
197+
},
198+
flowchart: {
199+
curve: 'basis'
200+
},
201+
themeCSS: '.edgePath .path { stroke-width: 4px; stroke: #555; }'
202+
});
203+
"""
204+
181205
autodoc_default_options = {
182206
"members": True,
183207
"undoc-members": True,

docs/source/tutorial_sources/zero-to-forge/1_RL_and_Forge_Fundamentals.md

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ graph TD
1111
subgraph Example["Math Tutoring RL Example"]
1212
Dataset["Dataset: math problems"]
1313
Policy["Policy: student AI"]
14-
Reward["Reward Model: scores answers"]
15-
Reference["Reference Model: baseline"]
14+
Reward["Reward Model:
15+
scores answers"]
16+
Reference["Reference Model:
17+
baseline"]
1618
ReplayBuffer["Replay Buffer: stores experiences"]
1719
Trainer["Trainer: improves student"]
1820
end
@@ -25,9 +27,11 @@ graph TD
2527
ReplayBuffer --> Trainer
2628
Trainer --> Policy
2729
28-
style Policy fill:#4CAF50
29-
style Reward fill:#FF9800
30-
style Trainer fill:#E91E63
30+
style Policy fill:#4CAF50,stroke:#fff,stroke-width:2px
31+
style Reward fill:#FF9800,stroke:#fff,stroke-width:2px
32+
style Trainer fill:#E91E63,stroke:#fff,stroke-width:2px
33+
34+
linkStyle default stroke:#888,stroke-width:2px
3135
```
3236

3337
### RL Components Defined (TorchForge Names)
@@ -76,7 +80,7 @@ Here's the key insight: **Each RL component becomes a TorchForge service**. The
7680
```mermaid
7781
graph LR
7882
subgraph Concepts["RL Concepts"]
79-
direction TB
83+
8084
C1["Dataset"]
8185
C2["Policy"]
8286
C3["Reward Model"]
@@ -86,7 +90,7 @@ graph LR
8690
end
8791
8892
subgraph Services["TorchForge Services (Real Classes)"]
89-
direction TB
93+
9094
S1["DatasetActor"]
9195
S2["Generator"]
9296
S3["RewardActor"]
@@ -173,11 +177,20 @@ Our simple RL loop above has complex requirements:
173177

174178
```mermaid
175179
graph LR
176-
A["Policy: Student AI<br/>'What is 2+2?' → 'The answer is 4'"]
177-
B["Reward: Teacher<br/>Scores answer: 0.95"]
178-
C["Reference: Original Student<br/>Provides baseline comparison"]
179-
D["Replay Buffer: Notebook<br/>Stores: question + answer + score"]
180-
E["Trainer: Tutor<br/>Improves student using experiences"]
180+
A["Policy: Student AI
181+
'What is 2+2?' →
182+
'The answer is 4'"]
183+
B["Reward: Teacher
184+
Scores answer: 0.95"]
185+
C["Reference: Original Student
186+
Provides baseline comparison"]
187+
D["Replay Buffer: Notebook
188+
Stores: question
189+
+ answer
190+
+ score"]
191+
E["Trainer: Tutor
192+
Improves student
193+
using experiences"]
181194
182195
A --> B
183196
A --> C

docs/source/tutorial_sources/zero-to-forge/2_Forge_Internals.md

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,35 @@ When you call `await policy_service.generate(question)`, here's what actually ha
1212

1313
```mermaid
1414
graph TD
15-
Call["Your Code:<br/>await policy_service.generate"]
15+
Call["Your Code:
16+
await policy_service
17+
.generate.route"]
1618
1719
subgraph ServiceLayer["Service Layer"]
18-
Proxy["Service Proxy: Load balancing, Health checking"]
19-
LB["Load Balancer: Replica selection, Circuit breaker"]
20+
Proxy["Service Proxy:
21+
Load balancing
22+
Health checking"]
23+
LB["Load Balancer:
24+
Replica selection
25+
Circuit breaker"]
2026
end
2127
2228
subgraph Replicas["Replica Management"]
23-
R1["Replica 1: GPU 0, Healthy"]
24-
R2["Replica 2: GPU 1, Overloaded"]
25-
R3["Replica 3: GPU 2, Failed"]
26-
R4["Replica 4: GPU 3, Healthy"]
29+
R1["Replica 1:
30+
GPU 0, Healthy"]
31+
R2["Replica 2:
32+
GPU 1, Overloaded"]
33+
R3["Replica 3:
34+
GPU 2, Failed"]
35+
R4["Replica 4:
36+
GPU 3, Healthy"]
2737
end
2838
2939
subgraph Compute["Actual Computation"]
30-
Actor["Policy Actor: vLLM engine, Model weights, KV cache"]
40+
Actor["Policy Actor:
41+
vLLM engine,
42+
Model weights,
43+
KV cache"]
3144
end
3245
3346
Call --> Proxy
@@ -126,13 +139,17 @@ responses = await policy.generate.route(prompt=prompt)
126139
```mermaid
127140
graph LR
128141
subgraph Request["Your Request"]
129-
Code["await service.method.ADVERB()"]
142+
Code["await service
143+
.method.ADVERB()"]
130144
end
131145
132146
subgraph Patterns["Communication Patterns"]
133-
Route[".route()<br/>→ One healthy replica"]
134-
CallOne[".call_one()<br/>→ Single actor"]
135-
Fanout[".fanout()<br/>→ ALL replicas"]
147+
Route[".route()
148+
→ One healthy replica"]
149+
CallOne[".call_one()
150+
→ Single actor"]
151+
Fanout[".fanout()
152+
→ ALL replicas"]
136153
end
137154
138155
subgraph Replicas["Replicas/Actors"]

0 commit comments

Comments
 (0)