Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
177 changes: 177 additions & 0 deletions src/components/YouTubeGrid.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
---
// A responsive grid of YouTube "lite embeds": each card shows the video's
// thumbnail as a facade and only loads the real (cookieless) player iframe
// when the reader clicks it. Fast, private, and dependency-free.
interface Video {
id: string;
title: string;
author?: string;
}
interface Props {
videos: Video[];
}
const { videos } = Astro.props;
---

<div class="yt-grid">
{
videos.map((v) => (
<figure class="yt-lite" data-id={v.id}>
<button
type="button"
class="yt-frame"
aria-label={`Play video: ${v.title}${v.author ? ` (${v.author})` : ""}`}
>
<img
class="yt-thumb"
src={`https://i.ytimg.com/vi/${v.id}/maxresdefault.jpg`}
data-fallback={`https://i.ytimg.com/vi/${v.id}/hqdefault.jpg`}
alt=""
loading="lazy"
width="1280"
height="720"
/>
<span class="yt-badge" aria-hidden="true">
<svg viewBox="0 0 24 24" width="26" height="26">
<path d="M8 5v14l11-7z" fill="currentColor" />
</svg>
</span>
</button>
<figcaption class="yt-cap">
<span class="yt-title">{v.title}</span>
{v.author && <span class="yt-author">{v.author}</span>}
</figcaption>
</figure>
))
}
</div>

<style>
.yt-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
gap: 1.1rem;
}
.yt-lite {
margin: 0;
display: flex;
flex-direction: column;
gap: 0.55rem;
}
.yt-frame {
position: relative;
display: block;
width: 100%;
aspect-ratio: 16 / 9;
padding: 0;
border: 1px solid var(--color-border);
border-radius: 10px;
overflow: hidden;
background: var(--color-surface-deep);
cursor: pointer;
-webkit-tap-highlight-color: transparent;
}
.yt-thumb {
width: 100%;
height: 100%;
object-fit: cover;
display: block;
/* Override the global `.prose img` frame — the button already frames it. */
border: 0;
border-radius: 0;
transition: transform 0.35s ease, filter 0.35s ease;
}
.yt-badge {
position: absolute;
inset: 0;
margin: auto;
width: 52px;
height: 52px;
display: grid;
place-items: center;
padding-left: 3px;
color: #fff;
background: color-mix(in oklab, #000 55%, transparent);
border: 1px solid rgba(255, 255, 255, 0.35);
border-radius: 999px;
backdrop-filter: blur(2px);
transition: background 0.25s ease, transform 0.25s ease;
}
.yt-frame:hover .yt-thumb,
.yt-frame:focus-visible .yt-thumb {
transform: scale(1.03);
filter: brightness(0.9);
}
.yt-frame:hover .yt-badge,
.yt-frame:focus-visible .yt-badge {
background: var(--color-accent);
color: var(--color-accent-ink);
transform: scale(1.08);
border-color: transparent;
}
.yt-frame:focus-visible {
outline: 2px solid var(--color-accent);
outline-offset: 2px;
}
.yt-cap {
display: flex;
flex-direction: column;
gap: 0.1rem;
line-height: 1.35;
}
.yt-title {
font-size: 13.5px;
font-weight: 600;
color: var(--color-text);
letter-spacing: -0.01em;
}
.yt-author {
font-family: var(--font-mono);
font-size: 11.5px;
color: var(--color-text-dim);
}
@media (prefers-reduced-motion: reduce) {
.yt-thumb,
.yt-badge {
transition: none;
}
.yt-frame:hover .yt-thumb,
.yt-frame:focus-visible .yt-thumb {
transform: none;
}
}
</style>

<script>
document.querySelectorAll<HTMLElement>(".yt-lite").forEach((fig) => {
// Some videos have no maxres thumbnail; fall back to the always-present one.
const img = fig.querySelector<HTMLImageElement>(".yt-thumb");
if (img) {
img.addEventListener(
"error",
() => {
const fb = img.dataset.fallback;
if (fb && img.src !== fb) img.src = fb;
},
{ once: true },
);
}

const btn = fig.querySelector<HTMLButtonElement>(".yt-frame");
if (!btn) return;
btn.addEventListener("click", () => {
const id = fig.dataset.id;
if (!id) return;
const iframe = document.createElement("iframe");
iframe.src = `https://www.youtube-nocookie.com/embed/${id}?autoplay=1&rel=0`;
iframe.title =
fig.querySelector(".yt-title")?.textContent || "YouTube video";
iframe.allow =
"autoplay; encrypted-media; picture-in-picture; web-share; fullscreen";
iframe.allowFullscreen = true;
iframe.style.cssText =
"width:100%;aspect-ratio:16/9;display:block;border:1px solid var(--color-border);border-radius:10px;";
btn.replaceWith(iframe);
});
});
</script>
33 changes: 33 additions & 0 deletions src/components/illustrations/anim/AnimRuntime.astro
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,39 @@
.wf .fire{font-size:11px;opacity:0;transition:opacity .4s}
.wf[data-frame="2"] .fire,.wf[data-frame="3"] .fire,.wf[data-frame="4"] .fire{opacity:1}
.wf .fire.a{fill:var(--color-accent)}.wf .fire.d{fill:var(--color-text-dim)}

/* ---------- #12 forward pass (full transformer) ---------- */
.fwd .ttl{margin-bottom:12px}
.fwd .col{display:flex;flex-direction:column;gap:7px;max-width:440px;margin:0 auto}
.fwd .st{display:flex;align-items:center;gap:10px;border:1px solid var(--color-border);background:var(--color-surface-deep);border-radius:9px;padding:9px 13px;opacity:.4;transition:opacity .4s,border-color .4s,background .4s,box-shadow .4s}
.fwd .lb{font-family:var(--font-mono);font-size:12.5px;color:var(--color-text-muted)}
.fwd .lb em{color:var(--color-text-faint);font-style:normal}
.fwd .st.mid{border-style:dashed}
.fwd .st.out{border-color:color-mix(in oklab,var(--color-accent) 25%,var(--color-border))}
.fwd .pred{margin-left:auto;opacity:0;transform:translateX(-5px);transition:opacity .5s,transform .5s}
.fwd[data-frame="1"] .st:nth-child(-n+1),.fwd[data-frame="2"] .st:nth-child(-n+2),.fwd[data-frame="3"] .st:nth-child(-n+3),.fwd[data-frame="4"] .st:nth-child(-n+4),.fwd[data-frame="5"] .st:nth-child(-n+6),.fwd[data-frame="6"] .st:nth-child(-n+7){opacity:1}
.fwd[data-frame="1"] .st.s1,.fwd[data-frame="2"] .st.s2,.fwd[data-frame="3"] .st.s3,.fwd[data-frame="4"] .st.s4,.fwd[data-frame="5"] .st.s5,.fwd[data-frame="5"] .st.s6,.fwd[data-frame="6"] .st.s7{border-color:color-mix(in oklab,var(--color-accent) 55%,transparent);background:color-mix(in oklab,var(--color-accent) 10%,transparent);box-shadow:0 0 14px color-mix(in oklab,var(--color-accent) 18%,transparent)}
.fwd[data-frame="1"] .st.s1 .lb,.fwd[data-frame="2"] .st.s2 .lb,.fwd[data-frame="3"] .st.s3 .lb,.fwd[data-frame="4"] .st.s4 .lb,.fwd[data-frame="5"] .st.s5 .lb,.fwd[data-frame="5"] .st.s6 .lb,.fwd[data-frame="6"] .st.s7 .lb{color:var(--color-accent)}
.fwd[data-frame="6"] .pred{opacity:1;transform:none}

/* ---------- #13 training pass (full transformer + backprop) ---------- */
.tp .fp-stage{display:flex;flex-direction:column;align-items:center;gap:13px}
.tp .ttl{margin-bottom:1px}
.tp .col{display:flex;flex-direction:column;gap:7px;width:100%;max-width:440px}
.tp .st{display:flex;align-items:center;gap:10px;border:1px solid var(--color-border);background:var(--color-surface-deep);border-radius:9px;padding:9px 13px;opacity:.4;transition:opacity .4s,border-color .4s,background .4s,box-shadow .4s}
.tp .lb{font-family:var(--font-mono);font-size:12.5px;color:var(--color-text-muted)}
.tp .pred{margin-left:auto;opacity:0;transform:translateX(-5px);transition:opacity .5s,transform .5s}
.tp .cmp{display:flex;align-items:center;gap:8px;flex-wrap:wrap;justify-content:center;font-family:var(--font-mono);font-size:12px;opacity:0;transition:opacity .45s}
.tp .cmp .err{color:var(--color-text-muted)}
.tp .cmp .err b{color:var(--color-accent)}
.tp .bp{font-family:var(--font-mono);font-size:11.5px;color:var(--d-teal);text-align:center;max-width:440px;line-height:1.5;opacity:0;min-height:16px;transition:opacity .45s}
.tp[data-frame="1"] .st:nth-child(-n+2),.tp[data-frame="2"] .st:nth-child(-n+3),.tp[data-frame="3"] .st:nth-child(-n+4),.tp[data-frame="4"] .st,.tp[data-frame="5"] .st{opacity:1}
.tp[data-frame="1"] .st.i1,.tp[data-frame="1"] .st.i2,.tp[data-frame="2"] .st.i3,.tp[data-frame="3"] .st.i4{border-color:color-mix(in oklab,var(--color-accent) 55%,transparent);background:color-mix(in oklab,var(--color-accent) 10%,transparent);box-shadow:0 0 14px color-mix(in oklab,var(--color-accent) 18%,transparent)}
.tp[data-frame="1"] .st.i1 .lb,.tp[data-frame="1"] .st.i2 .lb,.tp[data-frame="2"] .st.i3 .lb,.tp[data-frame="3"] .st.i4 .lb{color:var(--color-accent)}
.tp[data-frame="3"] .pred,.tp[data-frame="4"] .pred,.tp[data-frame="5"] .pred{opacity:1;transform:none}
.tp[data-frame="4"] .cmp,.tp[data-frame="5"] .cmp{opacity:1}
.tp[data-frame="5"] .bp{opacity:1}
.tp[data-frame="5"] .st{border-color:color-mix(in oklab,var(--d-teal) 50%,transparent);background:color-mix(in oklab,var(--d-teal) 9%,transparent);box-shadow:0 0 12px color-mix(in oklab,var(--d-teal) 16%,transparent)}
</style>

<script is:inline>
Expand Down
35 changes: 35 additions & 0 deletions src/components/illustrations/anim/Fig.astro
Original file line number Diff line number Diff line change
Expand Up @@ -228,3 +228,38 @@ const { name } = Astro.props;
</div>
</figure>
)}

{name === "forward" && (
<figure class="fp ill fwd" tabindex="0" data-dwell="2300"
data-captions='["Select each token’s embedding from the table.","Attention: every token pulls in context from the others.","Feed-forward: learned facts are folded into each token.","The same attention and feed-forward pair repeats through the middle layers.","The final layer applies attention and feed-forward one last time.","The last position is scored against the vocabulary to pick the next token."]'>
<div class="fp-stage">
<div class="ttl">forward pass · inference</div>
<div class="col">
<div class="st s1"><span class="lb">select embeddings</span></div>
<div class="st s2"><span class="lb">attention <em>· layer 1</em></span></div>
<div class="st s3"><span class="lb">feed-forward <em>· layer 1</em></span></div>
<div class="st mid s4"><span class="lb">layers 2 to 33 <em>· attention + feed-forward</em></span></div>
<div class="st s5"><span class="lb">attention <em>· layer 34</em></span></div>
<div class="st s6"><span class="lb">feed-forward <em>· layer 34</em></span></div>
<div class="st out s7"><span class="lb">dot product → next token</span><span class="pred pill">mat</span></div>
</div>
</div>
</figure>
)}

{name === "trainpass" && (
<figure class="fp ill tp" tabindex="0" data-dwell="2500"
data-captions='["A partial training sentence selects its token embeddings.","The full stack of layers runs forward, the same as at inference.","The model predicts a next token, often wrong early in training.","Score the guess against the real next token: how large is the error?","Backpropagate: nudge every weight, and the input tokens’ embeddings, in proportion to the error."]'>
<div class="fp-stage">
<div class="ttl">training · one step</div>
<div class="col">
<div class="st i1"><span class="lb">input <em>· “The cat sat on”</em></span></div>
<div class="st i2"><span class="lb">embedding lookup</span></div>
<div class="st i3"><span class="lb">layers 1 to 34 <em>· attention + feed-forward</em></span></div>
<div class="st i4"><span class="lb">dot product → prediction</span><span class="pred pill">dog</span></div>
</div>
<div class="cmp"><span class="mut">guess</span><span class="pill">dog</span><span class="ar">vs</span><span class="mut">actual</span><span class="chip">mat</span><span class="err">→ error <b>large</b></span></div>
<div class="bp">← backpropagate: nudge every weight and the input tokens’ embeddings, proportional to the error</div>
</div>
</figure>
)}
33 changes: 29 additions & 4 deletions src/content/blog/sre-guide-deploying-llms-part-1.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ draft: false

import AnimRuntime from "../../components/illustrations/anim/AnimRuntime.astro";
import Fig from "../../components/illustrations/anim/Fig.astro";
import YouTubeGrid from "../../components/YouTubeGrid.astro";

<AnimRuntime />

Expand All @@ -17,10 +18,30 @@ As SREs, we can deploy and ensure the reliability of a workload only because we

On the surface, LLMs look like microservices, because invoking one looks like you're just talking to an HTTP endpoint, but they're absolutely nothing like a regular microservice. Under the hood, an LLM is a hyper-parallelized matrix-multiplication beast that takes some know-how of machine learning, specifically deep learning, which I'm not going to go into. Frankly, understanding transformers opens the Pandora's box of neural networks, gradient descent, matrices, linear algebra, and probability and statistics: a very dry and steep learning curve, one that's hard to justify for SREs. ML engineers spend a good portion of their studies mastering all of this, and if you can, I do highly recommend building at least a high-level understanding when you have the time and energy. Once the concepts click, they're fairly simple, and also fascinating. If you do decide to go down this path, I highly recommend Grant Sanderson's videos on attention, which helped me build a mental model of what's going on:

- https://www.youtube.com/watch?v=KJtZARuO3JY
- https://www.youtube.com/watch?v=eMlx5fFNoYc
- https://www.youtube.com/watch?v=wjZofJX0v4M
- https://www.youtube.com/watch?v=9-Jl0dxWQs8
<YouTubeGrid
videos={[
{
id: "wjZofJX0v4M",
title: "Transformers, the tech behind LLMs | Deep Learning Chapter 5",
author: "3Blue1Brown",
},
{
id: "eMlx5fFNoYc",
title: "Attention in transformers, step-by-step | Deep Learning Chapter 6",
author: "3Blue1Brown",
},
{
id: "9-Jl0dxWQs8",
title: "How might LLMs store facts | Deep Learning Chapter 7",
author: "3Blue1Brown",
},
{
id: "KJtZARuO3JY",
title: "Visualizing transformers and attention | TNG Big Tech Day '24",
author: "Grant Sanderson",
},
]}
/>

But today I'm only going to touch these subjects superficially, and try to explain them in the simplest terms I can.

Expand Down Expand Up @@ -119,8 +140,12 @@ Finally, we sample: we draw one token at random using those probabilities as wei

That is the whole forward pass: text becomes tokens, tokens become embeddings, attention lets them influence each other, the feed-forward step folds in learned facts, a stack of these layers refines the result, and a final scoring-and-sampling step picks the next token, on repeat.

<Fig name="forward" />

Now step back and notice one thing about all of this. Everything we've walked through, the embedding lookup, then attention and the feed-forward step repeated across every layer, then the final scoring, is the structure of the transformer. And here's the point I want to land: this exact same structure is what runs during training. There's no separate training-time machine. At the start, every number in it is random: the embedding table, the Wq, Wk, Wv, Wu, and Wd in each layer, and the output table. We run this structure forward on a piece of training text to predict the next token, we measure how far off that prediction is from the token that actually came next, and we push that single "how off we are" number back through the whole structure, nudging every number in it in proportion to how much it contributed to the error. That's gradient descent, the same mechanism I described for the embeddings, except now you can see it's tuning everything at once, in one pass, repeated over and over across enormous amounts of text. Inference, the thing that actually serves your request, is just this same forward pass with all of those numbers now frozen in place.

<Fig name="trainpass" />

And this is exactly why an LLM is nothing like the microservice it resembles from the outside. A single response is not one cheap request; it's this entire stack run once per token, looping until the model decides to stop. That one fact, that the unit of work is a token and not a request, is what reshapes everything an SRE cares about: latency, throughput, batching, memory, and cost. In the next part, we'll start turning this understanding into the numbers we actually deploy against.

---
Expand Down