In TensorFlow, what is the difference between Session.run and Tensor.eval?
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
In TensorFlow 1.x, both Session.run() and Tensor.eval() execute graph computations and return concrete values. The difference is mostly about scope and convenience: Session.run() is the general execution API, while Tensor.eval() is a shortcut for evaluating one tensor in an available session.
Session.run Is the General Mechanism
TensorFlow 1.x builds a computation graph first and executes it later inside a Session. Session.run() is the method that actually asks the runtime to compute values.
It can fetch many kinds of graph outputs:
- one tensor
- several tensors
- operations with no returned value
- nested structures of graph elements
Session.run() is also the method you use when you need feed_dict, multiple fetches, or precise control over what part of the graph runs.
Tensor.eval Is a Convenience Shortcut
Tensor.eval() is a helper on a specific tensor object. Conceptually, it is just a shorthand for "run the session and fetch this tensor."
If a default session is active, you can even omit the explicit session= argument:
This is nice in notebooks and quick experiments, but it is not fundamentally different execution behavior.
Practical Differences
The easiest way to think about the difference is:
- use
Session.run()when the session is the main thing you are controlling - use
Tensor.eval()when you already have a specific tensor and want a shorter expression
Session.run() is more flexible:
Doing the same work with eval() is possible for one tensor at a time, but it is less natural when you need multiple outputs or want to emphasize the overall graph execution step.
Default Sessions Matter
One subtle point is that Tensor.eval() depends on a session being available. If you call it outside a default session and do not pass session=..., it fails.
That is why eval() is common in interactive code with InteractiveSession or a with sess.as_default(): block. In larger programs, many developers prefer Session.run() because it makes the session dependency explicit.
TensorFlow 2.x Changes the Story
In TensorFlow 2.x, eager execution is the default, so most code no longer uses sessions at all. Tensors are typically evaluated immediately, and you inspect values directly with methods such as .numpy() when working in eager mode.
That means Session.run() and Tensor.eval() are mostly legacy concepts today, used when maintaining older TensorFlow 1.x code or code written through tf.compat.v1.
Common Pitfalls
Using Tensor.eval() without a default session or explicit session= argument causes runtime errors because the tensor has nowhere to execute.
Assuming eval() is faster than run() is incorrect. It is mainly a convenience wrapper, not a different execution engine.
Calling eval() repeatedly for many tensors can be less clear and less efficient than fetching them together in one Session.run() call.
Mixing TensorFlow 1.x session-based examples with TensorFlow 2.x eager code causes confusion. Check which execution model the project is using first.
Trying to use Session.run() or Tensor.eval() in modern eager-only examples is usually unnecessary unless you are deliberately using tf.compat.v1.
Summary
- In TensorFlow
1.x, both APIs execute graph computations inside a session. - '
Session.run()is the general-purpose execution method.' - '
Tensor.eval()is a convenience shortcut for fetching one tensor's value.' - '
eval()needs a default session or an explicitsession=argument.' - In TensorFlow
2.x, eager execution usually replaces both patterns.

