C.W.K.
Stream
Lesson 07 of 08 · published

What Changes Across Backends

~8 min · backend

Level 0Keras Apprentice
0 XP0/97 lessons0/20 achievements
0/120 XP to next level120 XP to go0% complete

The line between portable and leaky

Knowing exactly what survives a backend switch and what doesn't is the difference between trusting the abstraction and being surprised by it. The good news: almost everything you write as Keras code is invariant. The differences only surface at the seam where you touch backend-native objects directly.

What stays the same

  • Model definition — Sequential, Functional, and Subclassing all identical
  • The training loop — model.compile() + model.fit()
  • Callbacks — EarlyStopping, ModelCheckpoint, and the rest
  • The .keras saving format
  • Every keras.ops operation

What changes (and where it leaks)

The differences below only bite when you reach past Keras to the engine — pulling a raw tensor out, placing it on a device by hand, or mixing in a backend-native library:

AspectTensorFlowPyTorchJAX
Tensor typetf.Tensortorch.Tensorjax.Array
Device mgmttf.device.to(device)jax.devices()
Layers areKeras layerstorch.nn.ModuleKeras layers
JIT compilationtf.functiontorch.compilejax.jit (default)

The practical rule: stay inside Keras + keras.ops and none of this column-shopping matters; the model is genuinely portable. The moment you cross into native code, mark that boundary clearly — it's the one place a backend swap can break you.

External links

Exercise

Write the same model + train loop under all three backends. Note any place you had to do something backend-specific. Aim for that list to be empty.

Progress

Progress is local-only — sign in to sync across devices.
Spotted a bug or have feedback on this page?Report an Issue

Comments 0

🔔 Reply notifications (sign in)
Sign inPlease sign in to comment.

No comments yet — be the first.