AI Infra Interviews logo
Coding for Infra / 12
mediumNewOpenAI

Tokens arrive as byte fragments and a character can span several. Write the decoder that streams text correctly.

A four-byte emoji split across three tokens will raise on every naive decode, and the fix is a buffer that holds the incomplete tail. The decoder in a dozen lines, the exception field that tells you exactly where to cut, and what to do when the stream ends mid-character.

Updated Sep 2026 · Grounded in real AI infrastructure interview loops and written to a senior-engineer editorial bar, with every number worked and every diagram hand-built.

A four-byte emoji split across three tokens will raise on every naive decode, and the fix is a buffer that holds the incomplete tail. The decoder in a dozen lines, the exception field that tells you exactly where to cut, and what to do when the stream ends mid-character.

more free answers with an account · no card

The concepts behind this question

Ranked by how closely each one overlaps this question's topic, so the first card is the thing to read if the answer above moved too fast.

Advanced
💻 Coding for Infra🔒 Premium
Parsing Kernel Traces and LogsThe profiler exported a 40 GB trace; the fleet emitted a terabyte of logs overnight; the interviewer hands you a text file of kernel records and asks which kernels dominated, per GPU, per stream. The problem is a parser plus an aggregation, and it is a test of three habits: streaming instead of loading, choosing the key you aggregate on before you write a line, and handling malformed input as data rather than as an exception. This page works the reported trace-classification problem end to end, derives the memory bounds of each design, and shows the generator-based structure that scales from a screen-sized file to a fleet.
Advanced
🔌 Networking & Storage🔒 Premium
Data Loading Pipelines for TrainingThe dataloader is the only part of a training job that runs on the CPU, the disk and the network at once, and it is the part most often found starving the GPUs. A pipeline that keeps 1,024 accelerators fed has to read sharded files sequentially, decode and tokenize in parallel workers, prefetch several batches ahead, pin memory for the PCIe copy, and do it deterministically enough to resume mid-epoch. The symptom of failure is a GPU at 30% utilization with nothing wrong on the GPU.
Foundational
🔌 Networking & Storage
Dataset Lifecycle: Ingest, Shard and RetainA training dataset is not a file, it is a pipeline with four stages and a retention policy, and each stage has a different bottleneck. Ingest is metadata-bound rather than bandwidth-bound. Tokenization is CPU work that should happen once offline rather than every epoch. Sharding decides whether the training read is a stream or a storm of small files. And retention decides how much of the bill is paid for bytes nobody reads.
Advanced
📐 AI Systems Design🔒 Premium
Evaluation and Data Pipeline InfrastructureBehind every model release is a pipeline that turns raw text into training shards and a harness that runs thousands of evaluation prompts against every checkpoint, and both are infrastructure problems with GPU-sized budgets. The data side is a batch system: dedup, filter, tokenize and shard petabytes with lineage. The eval side is a serving system in disguise: run a benchmark suite against a checkpoint in minutes, on shared GPUs, reproducibly, with results a researcher can trust. This page designs both, derives the compute and storage they need, and gives the reproducibility rules that separate a real harness from a script.
UP NEXT ON YOUR JOURNEY
FEDITOR'S NOTE

Scored on buffering the incomplete tail rather than decoding each piece, on using the decode error's start offset rather than guessing the boundary, and on a flush that handles a truncated stream.

DISCUSSION · 0

No comments yet — be the first to share your approach.