Go deeper
Everything above describes tracing from the outside: what freezes, what disappears, what gets recompiled. Seeing the mechanism from the inside is worth the extra hour, because a description of a tracer is not the same thing as watching one run. The three resources below take you from prose to source to a corpus large enough to trust the pattern instead of one running example.
The autodidax notebook builds a working tracer from scratch, implementing the same machinery this chapter has been describing in prose: tracers standing in for arrays, constants getting frozen into constvars, a jaxprThe traced program: one equation per primitive in single-assignment form, every shape and dtype stated.taught in /l/jaxpr → accumulating equation by equation. Reading about that process only gets you so far. Watching it happen, one traced call at a time, is what makes tracing stop feeling unexplainable.
Once the mechanism is familiar, the jaxprThe traced program: one equation per primitive in single-assignment form, every shape and dtype stated.taught in /l/jaxpr → documentation is the reference worth keeping open. It defines the grammar this chapter has been using informally: constvars, invars, equations, the exact vocabulary a tracer emits. When a jaxpr dump looks unfamiliar later in the course, this page is what resolves it, not this chapter.
For scale, the corpus x-ray in the gym keeps seventeen real programs open at once, each with its traced output on screen. Skimming a handful of them is a fast way to check whether the rules from this chapter, frozen constants, vanished branches, shape-locked recompiles, hold up outside the one running example you've been tracing by hand. One running example proves the mechanism exists; seventeen prove it's a rule, not a coincidence of the example you happened to be given.
Exercises
print inside a jitted function and call the function twice with the same shapes. Explain the single line of output using the words trace time and run time. Check yourself
01 You close over a numpy array and trace the function. Where does the array surface in the jaxpr, and where does it move if you pass it as an argument instead?
Closed over, it freezes into the constvars, matched against the consts list on the ClosedJaxpr. Passed as an argument, it becomes an invar, bound fresh on every call.
02 What is the fastest way to check whether your mental model of tracing survives contact with real programs?
The corpus x-ray in the gym: seventeen real programs with their traced output side by side. Skim a handful and test the rules, frozen constants, vanished branches, shape-locked retraces, against what actually printed.
Readings
- Autodidax: JAX core from scratch ↗ the working tracer this lesson asks you to read
- JAX · Understanding jaxprs ↗ the grammar, defined precisely; keep it open for the exercises