Eager execution runs each operation immediately and returns its result, much like ordinary R or NumPy code. This direct flow makes programs easier to inspect and debug, but often sacrifices performance compared with compiled computation. section 3.3.1 section 3.4.3
Immediate tensor operations
TensorFlow can create tensors, apply operations, and display each result as the code runs: create a matrix of ones, square it, take its square root, add results, multiply matrices, and concatenate tensors. No separate graph-building step is needed for these operations. section 3.3.1
Use eager execution as the practical baseline, then consider compilation when performance requires it.
- Debug operations in the R runtime before changing execution modes; the executed code remains visible and failures are easier to investigate. section 3.3.1
- Expect slower execution because operations run one after another instead of being fused or parallelized. section 3.3.1 section 3.4.3
- Compile TensorFlow functions with tf_function() only after debugging; the first call incurs compilation, while later calls can run faster. section 3.3.1
- Treat PyTorch eager execution as the normal approach in practice, because torch$compile() may fail for some models or provide no speedup. section 3.4.2
a <- tf$ones(shape(2, 2)) b <- tf$square(a) #1 c <- tf$sqrt(a) #2 d <- b + c #3 e <- tf$matmul(a, b) #4 f <- tf$concat(list(a, b), axis = 0L) #5
Inspect a sequence of TensorFlow tensor operations that execute directly and produce values immediately. section 3.3.1




