Chao Ma (@ickma2311) profile picture

Applied Math × AI × Chip Architectures Exploring the foundations behind modern intelligence systems. Sharing clear technical insights & visual explanations.

San Ramon
Joined November 2023
∇ CMU Advanced NLP · Lecture 15: Reinforcement Learning Fundamentals Supervised fine-tuning imitates static tokens. Policy gradients optimize sequence-level rewards from model rollouts. Four mechanics from Lecture 15 and its saved CartPole notebooks explain why stabilization matters: - Environment dynamics drop out. Factoring trajectory log-probabilities zeros out unknown transition gradients. - Baselines center positive rewards. In Slide 38, a 0.30 score becomes -0.45 on an easy summary. - Single saved CartPole runs show the gap. Adding a value baseline solves in 572 episodes (inferred index 571) vs. 1,141 without. - PPO clips surrogate gain outside [0.8, 1.2]. It removes incentives for oversized updates without hard-bounding ratios. My note: ickma2311.github.io/ML/NLP/c…
124
∇ MIT 6.874 · Lecture 24: Reverse-Engineering Visual Cortex and Recurrent Neural Memory Every 200 ms gaze glance covers roughly 10 degrees. Within 100 ms, primate IT cortex carries linearly decodable object identity. In Lecture 24, James DiCarlo and Jason Z. Kim explore two sides of brain computation. - Task optimization matches cortical depth: Hand-crafted HMAX stalled at 0.24 variance in V4. Task-trained HMO Layer 3 hits 0.52 on V4. HMO Top Layer reaches 0.48 on IT. - Closed-loop V4 control via synthesis: Model-synthesized images super-activated 68% of V4 sites (1% chance). One-hot subpopulation control hit 76% success (1% chance). Models still predict only 54% of novel synthetic responses. - Fixed reservoirs learn manipulable memories: Trained only on shifts c = 0 to 3, reservoirs extrapolate to +/-20. Trained only on stable decays at rho = 23 and 24, stepping c triggers two-wing switching. Our constructed RK4 check finds the stability flip near c = 1.7453. My note: ickma2311.github.io/ML/Biolo…
1
11
327
∇ CMU Advanced NLP · Lecture 14: Research Skills and Experimental Design Define what could prove you wrong before you run compute. Three numbers from Lecture 14 and Evan Miller (2024) show why design comes first: - Halving the target gap quadruples eval size. In power.ipynb (80% power, alpha = 0.05), detecting 2.0 pp takes 2,279 paired items. Detecting 1.0 pp takes 9,115 (4.0x). - Resampling K outputs hits a variance floor. At fixed n = 198, K = 10 cuts MDE from 13.2% to 7.5%. Question variance omega^2 still leaves a 6.64 pp floor. - Raw agreement hides class skew. In iaa.ipynb (674 simulated items), 88.6% agreement gives kappa = 0.772. In a constructed check at 90% skew, 85% agreement drops kappa to 0.167. My note: ickma2311.github.io/ML/NLP/c…
2
7
459
∇ MIT 6.874 · Lecture 23: Pharmacodynamic State Space Models for Disease Progression Between 2008 and 2015, U.S. hospital EHR adoption climbed from 9.4% to 83.8%. Yet when modeling rare cancers like multiple myeloma (1,143 patients, 66% missing lab entries), unconstrained neural state-space models (51K–77K params) overfit, while linear SSMs (7K params) miss nonlinear relapse. In MIT 6.874 Lecture 23, Rahul G. Krishnan shows how SSM_PK-PD (Hussain, Krishnan, & Sontag, ICML 2021) builds a structured middle ground: - Therapy clocks: A global clock tracks total treatment time, while a local clock resets to zero whenever progression triggers a new line of therapy. - Neural PK-PD mechanisms: Soft attention queried by latent state Z_{t-1} blends three mechanisms—baseline modulation (g_1), log-cell kill for gradual relapse (g_2), and piecewise treatment exponential sigmoids (g_3). - Small-sample generalization: On synthetic data at N=100, SSM_PK-PD reaches 55.34 nats test NELBO (beating 51K SSM_NL at 69.04 by 13.70 nats). On 282 held-out multiple myeloma patients, 23K-parameter SSM_PK-PD scores 61.54 nats—beating 7K Linear (74.22), 51K NL (79.10), and 77K MOE (73.44), with >10-nat NLL gains on 130/282 patients vs. NL (12 losses). My note: ickma2311.github.io/ML/Biolo…
2
198
∇ CMU Advanced NLP · Lecture 13: Evaluation and Benchmarks In a bare score table, Dreadnought leads Galleon 2-to-1 across HumanEval (-3.1 pp), MGSM (-2.7 pp), and MATH (+2.5 pp). Add statistical error bars, and the leaderboard flips: - Only MATH (+2.5 pp, 95% CI (+1.2, +3.8) pp) excludes zero; HumanEval (N=164, -7.2 to +1.0 pp) and MGSM (-6.1 to +0.7 pp) are indistinguishable from sampling noise. - Naive i.i.d. SEs fail whenever questions share passages or translations: on empirical evaluations, clustering widens SE by 3.05x on DROP (F1 pts), 1.88x on MGSM (pp), and 1.10x on RACE-H (pp). - Even before statistics, loss diverges from task solve rate (LLaMA SIQA, AlphaCode), and every model plotted on held-out GSM1k drops below parity (up to -10.2 pp). My note: ickma2311.github.io/ML/NLP/c…
2
176
∇ MIT 6.874 · Lecture 22: Image Registration & Pathology Detection Why does aligning two 3D brain MRIs take ~2,350 to 9,000 s with classical solvers, when a single forward pass can do it in 0.5 s on GPU? MIT 6.874 Lecture 22 pairs two medical-imaging architectures that replace brute-force supervision with structure: - Amortized 3D registration (Adrian Dalca): VoxelMorph learns shared CNN weights across 7,000 training volumes, cutting per-pair runtime from ~2,350–9,000 s (NiftyReg / ANTs CPU) to 51 s CPU and 0.5 s GPU. SynthMorph trains on synthetic shapes for cross-modality robustness, and HyperMorph uses a hypernetwork to sweep smoothness weight λ in 147 GPU-h instead of 765 GPU-h (~5.20x faster). - Dual-encoder polyp segmentation (Ahmed Mohammed): Y-Net pairs a pretrained VGG19 encoder with a randomly initialized encoder on ASU-Mayo colonoscopy frames, raising recall from 68.2% to 84.4% and F1 from 79.8% to 85.9%. - Weakly supervised capsule endoscopy: Clinical exams capture ~50,000 frames, so PS-DeVCEM (EndoscopicMIL) trains on segment-level bag labels across 14 classes, pairing Residual LSTMs, temporal attention, and dual sub-bag self-supervision to lift average F1 from 0.066 (SIL) to 0.551. My note: ickma2311.github.io/ML/Biolo…
1
5
307
∇ CMU Advanced NLP · Lecture 12: Multimodal Modeling II To let one autoregressive transformer generate both text and images, raw pixels hit an immediate sequence-length wall: a 1024×1024 RGB image is 3,145,728 subpixel tokens, and even 256×256 is 65,536 spatial steps (196,608 RGB subpixels, derived). - VQ-VAE (van den Oord et al. 2017): snaps CNN feature grids to a learned codebook via nearest-neighbor lookup and trains across the non-differentiable argmin using straight-through gradient copying plus codebook and commitment terms, compressing an image to a 32×32 = 1,024 token grid. - VQ-GAN + Early Fusion (Esser et al. 2021; Chameleon; Liquid): swaps pixel MSE for perceptual LPIPS and a patch GAN discriminator so discrete visual codes sharpen fine detail and share one vocabulary with BPE text tokens. - Diffusion (DDPM, DALL-E 2): offers a continuous denoising alternative, pairing a CLIP-space diffusion prior p(z_I | z_T) with a pixel-space diffusion decoder. My note: ickma2311.github.io/ML/NLP/c…
155
∇ CMU DLSys · Lecture 23: Model Deployment Hand-writing kernel libraries for every phone GPU, CPU vector unit, and NPU does not scale. ML compilers replace per-backend operator catalogs by putting graphs and loops inside one IRModule: - Graph + loop lowering: High-level transformations outline fused ops like @dot-add, then loop fusion folds zero-init and bias add into the reduction—cutting our constructed 16×16 float32 buffer check in half (2,048 B → 1,024 B, 3 passes → 1). - Decoupled schedules: From one tvm.compute matmul spec, split, reorder, and thread binding emit naive, 8×8 tiled (512 MACs per 128 loaded elements = 4.0 MACs/elem), or scratchpad DMA kernels. - Learned cost models: Because edge hardware benchmarking is slow, an ML cost model f_hat(e, c) predicts latency from measured runs f(x) to guide schedule search. My note: ickma2311.github.io/ML/DLSys…
2
1
9
541
∇ MIT 6.874 · Lecture 21: Image-Based Cell Phenotyping Why did five per-group U-Nets need 20 hours of tuning and still trail a CellProfiler expert on cell segmentation? MIT 6.874 Lecture 21 (Juan Caicedo) breaks microscopy profiling into two distinct ML problems: - Generic segmentation across image-group shift: In the 2018 Data Science Bowl benchmark (106 scored images across 5 image groups; presented as a 100-image scenario in the talk), per-group U-Nets reached 0.620 mean per-image F1 @ 0.7 IoU (20 h) and CellProfiler Expert reached 0.743 (3 h), while the pretrained top DSB model hit 0.816 (0 h setup). - Weakly supervised embeddings: Without ground-truth phenotype labels, DeepProfiler trains a CNN to classify single-cell crops by applied treatment, then averages embeddings per well. On Cell Painting benchmarks (BBBC037, BBBC022, BBBC036), learned features beat classical features across every top-connection cutoff (e.g., ≈30× vs. ≈9× at top 0.4% on BBBC037). - Batch deconfounding via GRL: Plate layout and artifacts confound treatment signals. Adding a Gradient Reversal Layer (backward × −λ) penalizes batch-predictive encoder features, visibly mixing dataset labels across training and validation projections. My note: ickma2311.github.io/ML/Biolo…
2
196
∇ CMU Advanced NLP · Lecture 11: Multimodal Modeling I Extending a text-only LLM to read images starts with one representation problem: turning H×W×C pixels into a token sequence a transformer can process alongside words. - ViT (Dosovitskiy et al. 2020): splits images into P×P patches (224×224 with P=16 gives 196 patches + 1 CLS = 197 tokens in ViT-B/16) and passes them through a standard transformer encoder. - CLIP (Radford et al. 2021): trains parallel image and text encoders via symmetric InfoNCE on 400M (image, text) pairs. Zero-shot CLIP beats a ResNet-50 linear probe on 16/27 datasets (e.g., StanfordCars +28.9 pp) yet trails sharply on spatial and counting tasks (EuroSAT −37.1 pp, KITTI Distance −34.0 pp, CLEVRCounts −18.2 pp). - LLaVA & Molmo: project CLIP ViT patch tokens into the LLM embedding dimension and compute next-token loss on text only. Molmo pools 24×24 patches (ViT-L/14 336px) by 2×2 to 144 vectors per view (1,872 across 1 full + 12 crops before markers) and grounds answers in 0–100 image-relative coordinates. My note: ickma2311.github.io/ML/NLP/c…
1
1
17
811
∇ CMU DLSys · Lecture 22: Customizing Pretrained Models Retraining a multi-billion-parameter model per task or schema does not scale. Instead of touching every weight, customization attaches at one of three interfaces along a frozen forward pass: - Input & conditioning embeddings: CLIP aligns image–text pairs for conditional diffusion (τθ(c) on a reverse-time SDE), while MiniGPT-4 and LLaVA project visual tokens alongside text embeddings in the LLM sequence. - Zero-initialized parallel branches: ControlNet (locked block + trainable copy gated by zero convolutions) and LoRA (frozen W + rank-r BA) output exact zero at step 0, while outer ControlNet weights and LoRA B can update immediately. In a constructed check for a 4096×4096 layer at rank 16, LoRA reduces trainable weights 128× (131,072 vs. 16.78M, 0.781%). - Output logits: XGrammar speeds constrained JSON/CFG decoding by splitting vocabulary masks per stack top—>99% context-independent tokens cached ahead of time, <1% context-dependent outliers checked at runtime—so disallowed tokens receive −∞ before softmax. My note: ickma2311.github.io/ML/DLSys…
137
∇ MIT 6.874 · Lecture 20: Imaging Applications in Healthcare An end-to-end CNN detecting heart failure from pathology biopsies hit 0.97 AUC (Cohort 1: 104 train, 105 test)—versus 0.74 for two cardiac pathologists. On a second cohort from the exact same hospital and same scanner, its AUC fell by 0.22 to 0.75 after a remote scanner software upgrade. Both speakers in this lecture—Anant Madabhushi (cancer pathology) and Bree Aldridge (tuberculosis imaging and drug combinations)—converged on the same engineering lesson: - Confine deep learning to segmenting biological primitives (nuclei, glands, collagen fibers), then model clinical risk with explicit, inspectable geometry like local stromal collagen orientation entropy (CFOD-TS). - In noisy M. tuberculosis microscopy, CNNs lost to simpler statistical pipelines: dedicating 25% of imaging time to untreated controls for batch whitening (TVN), tracking quartile heterogeneity features, and running 70 consensus k-NN trials reached 94% reference and 76% CV accuracy across 34 drugs (5 MoA classes) and uncovered a metabolic-state-dependent bedaquiline phenotype. - For high-order drug combinations, geometric sampling (DiaMOND) measured 175 TB regimens (165 multidrug) across 8 environments—and exploratory PCA + Random Forest showed potency metrics (Einf, GRinf, AUC25) in lipid-rich and acidic conditions, not synergy, drove BALB/c mouse relapse classification (test AUC 0.75–0.94). My note: ickma2311.github.io/ML/Biolo…
12
498
∇ CMU Deep Learning Systems, Lecture 21 · Generative Models Implementation The target generator has a weight of 2 where the trained generator has about −0.07. That looks like a bad fit until you ask what the discriminator can observe. It sees points. Rotating or reflecting the standard Gaussian noise before applying the target weights can change individual weights while preserving the entire cloud’s distribution. In this two-dimensional example, the target cross-covariance is 1.90. The saved model gives 1.97. That comparison says more about the fit than matching weights entry by entry. My note: ickma2311.github.io/ML/DLSys…
1
11
370
CMU Advanced NLP — Lecture 10: Retrieval and RAG Two retrievers can find the same evidence and rank it very differently. In a constructed example, there is one relevant passage in the corpus. Put it first or third among three results: Recall@3 stays at 1 and Precision@3 stays at 1/3. But nDCG@3 falls from 1 to 0.5. That still measures the ranking, not whether the generator's answer follows from the passage. The course notebook illustrates this gap: a saved answer lists the instructor and seven of eight assistants without identifying their roles; the omitted assistant appears in the retrieved passage. The article connects datastore construction, contrastive retrieval training, context limits, and claim support. It also works through why RAG-Sequence and RAG-Token assign different probabilities to the same two-token target. My notes: ickma2311.github.io/ML/NLP/c…
1
3
27
837
CMU Advanced NLP — Lecture 8: Fine-Tuning and Distillation Keeping only a teacher’s top token can reverse a student’s learning signal. In a constructed example, the teacher assigns probabilities (0.6, 0.3, 0.1) over tokens (A, B, C), while the student assigns (0.5, 0.25, 0.25). Soft-target cross-entropy gives logit gradients (−0.1, −0.05, +0.15). Replacing the teacher with the one-hot top-token target gives (−0.5, +0.25, +0.25). Token B changes sign. The same distinction matters for complete answers. Samples from the unchanged teacher estimate the teacher-to-student cross-entropy; beam search, temperature changes, and filtering generally change the target distribution. The lecture also separates what can change from what is scored: LoRA restricts a weight update, while a response-loss mask selects prediction positions. A frozen weight still participates in computation; a prompt excluded from the loss can still supply context. My notes: ickma2311.github.io/ML/NLP/c…
1
5
16
618
CMU DLSys — Lecture 20: Generative Models Where does the training target come from when a random vector has no “correct” image? A GAN learns a discriminator. In the discriminator update, generated samples have target 0. In the non-saturating generator update, they have target 1: update G through D while keeping D’s parameters fixed. Detaching the whole path would remove the signal G needs. CycleGAN adds another constraint. Two discriminators check whether translated images fit their destination domains; cycle losses check whether translating out and back recovers the input. Matching distributions and round trips still does not identify a unique semantic mapping. Diffusion creates a target by sampling noise: xₜ = γₜx₀ + σₜε. The network predicts ε from (xₜ, t). Under squared error, the optimum averages over possible corruptions consistent with that input; it need not recover each sampled noise realization exactly. The basic GAN samples in one generator pass. The diffusion models discussed here use repeated learned reverse steps, with approximation error from the model and sampler. Step count alone does not establish a quality or latency ranking. My notes: ickma2311.github.io/ML/DLSys…
10
497
CMU Advanced NLP — Lecture 7: In-Context Learning and Prompting A model writes Python for 25 punches/minute, 5 rounds, and 3 minutes/round. Its saved program multiplies 5 by 25. An interpreter would return 125; the problem requires 375. This is a saved example in the course notebook, not a benchmark. The notebook generates and prints code—it does not execute the generated program. The distinction carries through the lecture. Demonstrations change a model's context without updating its weights. Chat templates specify how messages become input. A reasoning trace can add computation without guaranteeing correctness, and a program can faithfully compute a wrongly translated problem. Prompt search adds another boundary: examples used to choose the prompt are no longer an independent final test, even when the model's weights stay fixed. My note: ickma2311.github.io/ML/NLP/c…
1
18
586
MIT 6.874 — Lecture 17: Protein Folding A distance predictor can be locally plausible and globally impossible. Suppose it predicts AB = 4 Å, BC = 4 Å, and AC = 10 Å. No triangle has those sides. If the first two distances stay fixed, AC can be at most 8 Å. This is a constructed geometry example, not protein measurements. It explains why predicting a residue-pair map and building a structure are separate problems: all the pair predictions must fit into one object. The lecture connects three approaches: surface fingerprints for interactions, learned contact/distance maps for structure, and differentiable geometry that lets the final structure error train the predictor. Even a globally consistent structure needs more checks. Pair distances cannot distinguish a structure from its mirror image, and a surface match does not establish binding. My note: ickma2311.github.io/ML/Biolo…
8
315
CMU Advanced NLP — Lecture 6: Pretraining Filtering changes what a model learns even before the first gradient update. A constructed example: start with 800 general-web and 200 math token units. Retain 25% of general web and 80% of math. The corpus shrinks to 360 units, but math’s share rises from 20% to 44.4%. No new math content was added. The retention rates here are token-weighted, and there is no later resampling. Different sampling weights would change the mixture again. Maximum likelihood fits the distribution presented to it. A classifier that favors educational text therefore changes the learning target; “cleaner” does not automatically mean better for every domain. Sean Welleck’s lecture connects that data choice to the prediction objective and the compute budget. For dense Transformers, C ≈ 6ND is a useful first-order arithmetic estimate: more parameters leave fewer training tokens at fixed compute. Equal estimated FLOPs still do not imply equal loss or runtime. My note: ickma2311.github.io/ML/NLP/c…
1
5
38
1,329