Repository navigation
fix(probas,#8081): PyMC-6-Debugging §7 — exercise debug loop + make 'correct' model correct - #8366
Conversation
…l actually correct
Cell model_corrige used observed=50 (single obs) → sigma unidentified → committed output showed 573 divergences while prose claimed 'bien specifie'. Now n=30 obs: 0 divergences, R-hat 1.0, ESS 4684. Cell 36 had buggy model commented out ('DECOMMENTEZ POUR VOIR') → debug loop was prose not exercised. Now runs buggy model (shows prior crushes data, m~0 vs data~25, 0 div) then corrected. Deeper finding (mirrors Infer-6 #8349): bug NOT caught by divergences (both 0) but by comparing posterior to data. Hybrid reconstruct from origin/main, only cells 33-37 changed, H.3 1/1 PASS, C.1 0 violations.
Refs #8081. See #8052, #8349 (twin Infer-6 class).
Co-Authored-By: Claude-Code <noreply@anthropic.com>
Golden-Set Execution (H.7 P3)✅ 8/8 notebooks passed (certified reproducible)
Pinned lockfile: |
Notebook PR Validation: PASS
Checks: H.1 (no errors), H.3 (execution_count), C.1 (no banned patterns) |
clusterManager-Myia
left a comment
There was a problem hiding this comment.
[NanoClaw] structural review (glm-5.2 budget: file-list + 1 load-bearing notebook, base↔head content-hash diff + full read of the 5 replaced cells, no full patch)
CoursIA #8366 fix(probas,#8081): PyMC-6-Debugging §7 — exercise debug loop + make 'correct' model correct
head 3dc173a53c86, base f79034711e75, +133/-158, 1f PyMC-6-Debugging.ipynb (Python/PyMC). Author jsboige ≠ my identity → 0 self-review conflict. 0 secret, 0 leak, 0 CJK (whole-notebook scan clean).
LGTM deep — this fixes a real latent bug AND upgrades the pedagogy. Two things in one PR, both right:
1. The title's claim is accurate: the base "correct" model was actually broken. Compared the 5 removed base cells vs the 5 new head cells (content-hash diff, cell count 43→43):
- BASE[34] (the "modèle corrigé" reference) used
observed=50— a single scalar, not the n=30 array the surrounding prose described. Estimating bothmoyenneandsigmafrom one observation makes σ under-identified → exactly the funnel/NUTS-divergence pathology the notebook's own §2.2 warns against. The base markdown BASE[37] even (incorrectly) framed this as fine: "σ estimé à partir d'une seule observation." That's teaching the wrong reflex. - HEAD[34] fixes it:
observed=donneeswheredonnees = rng_obs.normal(loc=25, scale=8, size=30)— 30 observations → σ identifiable. With an explicit in-code comment explaining why n=30 (single obs → σ under-determined → funnel). Output recovers the data-generating params: moyenne 25.136±1.173, σ 6.443 (slight downward bias vs true 8 = expected n=30 sampling variance), 0 divergences, R̂=1.0, ESS 4684. ✓ Sound.
2. The debug exercise is made observable. BASE[36] had the buggy model commented out ("DECOMMENTEZ POUR VOIR") — so a student running the notebook never saw the failure. HEAD[36] makes the buggy model actually run and print its symptom: m ~ 0.001 (the Normal(0, sigma=0.01) prior crushes the data which is ~25) while reporting 0 divergences — the "silent trap" the closing lesson needs. Then it runs the corrected model showing moyenne ~ 25.1. The pedagogical pivot ("compare posterior to the DATA, not to divergences") lands because both models genuinely execute.
Verification: ec 11→12→13 (the PR's cells) clean and monotonic; the ec=5 gap and ec=6 duplicate earlier in the notebook are pre-existing (cells [2]-[31] unchanged by this PR), not introduced here. No new ec-doublon. HalfNormal-vs-Normal for σ reasoning correct (σ>0 constraint). Prior-shrinkage mechanics correct (Normal(0,0.01) is ~±0.02 → data at 25 is ~1250σ away, posterior stays at prior). rule 6 respected (the 5 replaced cells are the changed region; surrounding 38 cells byte-identical).
▼ NIT — chain-count inconsistency in the debug demo. HEAD[36] corrected model runs chains=2 (draws=2000) while the HEAD[34] reference runs chains=4. PyMC prints the "We recommend running at least 4 chains" warning, visible in the output of [36]. Minor (the debug point doesn't need 4 chains), but a student copying the corrected snippet gets a noisier R̂. Consider chains=4 in [36] too, or a one-line note that the debug demo deliberately uses fewer chains for speed. Non-blocking.
△ Cosmetic: the corrected-model code block is duplicated between [34] (reference) and [36] (debug-then-fix) — intentional for a self-contained exercise cell, just noting the repetition in case a helper refactor is ever wanted.
Net: a genuine correctness fix (single-scalar observed → n=30 array) wrapped in a better exercise (silent-failure made visible). The kind of change that earns its LGTM. Mergeable.
…clear fleet-red gate) (#8372) The Twin parity audit gate (#8185 = BLOCKING) was fleet-RED on every open PR because 15 registered twin pairs drifted on origin/main: merged PRs that modify a registered twin notebook (citations, Prong-B enrichment, determinism seed, metadata.cost rollout, nbformat cell-id fix) did not rebaseline their last_audit.{python,csharp}_sha, so the recorded SHA lagged the merged blob. G.8 audited resync (NOT rubber-stamped) — every drift traces to a NAMED merged PR (verified via git log -- <notebook> between recorded and current blob): - Coordinated twin updates (parallel PRs both sides): Z3-06 (#8328+#8353), ML-7 (#8284 both), Probas-6 (#8366+#8349), Probas-8 (#8330+#8355), Probas-11/#8325 both, Probas-13 (#8344+#8360), Probas-15/16/17 citation twins. - Framework-specific infra (asymmetric, benign): Probas-3/4/12 C#-only = #8323 metadata.cost rollout (PyMC twins have no such frontmatter yet); CSP-3 PY-only = #8252 OR-Tools CpSolver seed (C# twin uses Choco Solver, deterministic default search — different lib, no parity break, spot-checked); Search-3 PY-only = #8324 IDA* prose reframe + #7252 FR accents. Independently re-confirms the G.1 firsthand claim (jsboige c.03:58, po-2023 c.04:08 merge-sim) on the CURRENT origin/main state (8743caf): all 15 are stale-sha-only, ZERO content drift that broke semantic parity. Surgical method (NOT check_twin_parity.py --update): --update yaml.safe_dump's the ENTIRE curated YAML -> 1350-line churn + strips the header comment block (measured). Instead: context-free exact string replacement of each old->new 40-char git blob SHA (all 25 old shas unique, verified -> unambiguous). Result: +25/-25 = 50 lines, ONLY python_sha/csharp_sha fields changed; header comments, known_differences prose, indentation, LF line-ending byte-preserved (GATE A-C). Proof: check_twin_parity.py --check -> OK=39 DRIFT=0 exit 0 (CI-green). See #8264 (resync of existing drifts; 'going-forward enforcement' = documented precedent #8057, separate concern). See #8057, #8185. Co-authored-by: Claude <noreply@anthropic.com>
fix(probas,#8081): PyMC-6-Debugging §7 — exercise the debug loop + make the "correct" model actually correct
Grain: MED/notebook-python — lane myia-po-2025:CoursIA — prev: MED/notebook-dotnet (Z3-06-Csharp Prong-B #8353).
Firsthand audit of the PyMC twin of Infer-6 (whose §7 gap was backfilled by po-2026 in #8349). Same gap-class, two defects in
PyMC-6-Debugging.ipynb§7 "Exemple guide : Debugger un Modèle":Defect A — the "correct" example model was itself broken (doc-honesty)
Cell
model_corrige("Modele d'estimation bien specifie / déjà corrigé") usedobserved=50— a single scalar observation. With n=1,sigmais unidentified → Neal's funnel → the committed output literally showed 573 divergences + R-hat > 1.01 + ESS < 100, while the prose (cell 33) claimed it showed "comment spécifier correctement un modèle". A debugging notebook teaching that 573 divergences = "well-specified" is an integrity bug.Firsthand-verified (coursia-ml-training kernel, PyMC 5.28.5,
random_seed=42, determinism confirmed): the single-obs model reproduces divergences (49 at 500 draws; 573 at the notebook's 2000/4). A well-specified version with n=30 observations samples clean: 0 divergences, R-hat 1.0, ESS 4684,moyenne25.14 (hdi [22.9, 27.3]),sigma6.44. Fix: cell 34 now uses n=30 simulated data → the "bien spécifié" claim is true.Defect B — the debug loop was described, not exercised
Cell 36 had the buggy model commented out ("
# DECOMMENTEZ POUR VOIR LES PROBLEMES") and immediately ran the corrected version — so the student never sees the buggy model fail. The debug loop (cassé → diagnostic → fix) was prose, not demonstrated.Fix: cell 36 now runs the buggy model and shows its real symptom, then the corrected model, side by side:
The deeper pedagogical finding (mirrors Infer-6 #8349): the bug is NOT caught by divergences — both models have 0 — but by comparing the posterior to the data (m≈0 vs data≈25). A hyper-concentrated prior is a silent trap: the sampler runs cleanly yet the posterior ignores the data. This is the reflex the §7 debugging section exists to teach.
Validation
nbconvert --execute(kernelcoursia-ml-training, PyMC 5.28.5, matching the notebook's committed env): 0 errors, real captured outputs (stdout+stderr interleaved correctly).validate_pr_notebooks.py origin/main <path>: 1/1 PASS (13 code cells).origin/mainbaseline + surgical replace of cells 33-37 (intro md + cell34 code + challenge md + cell36 code + analysis md). Verified by-id that only cells [33,34,35,36,37] changed — §8/§9 exercises + summary intact. ec preserved (34=11, 36=12; the pre-existing ec anomaly on cells 15/18 is in origin/main, untouched).raise/assert False/1/0scan clean).json.dumps(indent=1).Context
PyMC twin of Infer-6 (#8349). Part of the #8081 fidelity audit — PyMC-6 verdict: gap was localized to §7 (backfilled here); the rest (§2.2 divergences, §3 NUTS-vs-ADVI, §4 ArviZ diagnostics, §5 priors, §6 checklist) is faithful and rich. See #8081, See #8052.