InvalidArgumentError input_10 is both fed and fetched
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
The TensorFlow error saying a tensor is both fed and fetched means one tensor is being treated as input and output in the same session call. This usually appears in TensorFlow graph execution code where run arguments are assembled dynamically. The fix is to separate placeholder inputs from computed outputs and enforce this boundary in wrapper code.
Understand Feed Versus Fetch Roles
In graph mode, feed_dict supplies values for placeholders or feedable tensors. Fetch list requests tensors to compute and return.
If the same tensor appears in both, TensorFlow raises an InvalidArgumentError.
A minimal graph example:
This works because x is fed and y is fetched.
How the Error Usually Appears
The error often appears in shared helper code, not directly where tensors are defined. A wrapper may accidentally merge input tensors and output tensors into one list.
Example anti-pattern:
The fix is not only at one run call. It requires cleaning the run argument construction path.
Build Explicit Run Interfaces
Avoid generic run wrappers that accept arbitrary tensor lists. Use typed helpers with fixed feed and fetch contracts.
When interfaces are explicit, feed and fetch overlap is harder to introduce.
Add Runtime Assertions in Legacy Code
If you cannot refactor immediately, add validation before calling session run.
This produces clearer failures than deep TensorFlow stack traces.
Inspect Graph and Tensor Naming
Large graphs with reused names can hide mistakes. Print tensor names and operation types while debugging.
Clear naming reduces confusion in feed and fetch wiring.
Migration Path to TensorFlow 2
If feasible, migrate graph-mode execution to eager or tf.function. This class of error is less common in modern execution style.
Even partial migration can simplify debugging and reduce session wrapper complexity.
Test for Regression
Add unit tests around wrapper behavior, not only model math.
In real tests, assert that feed keys match expected placeholders and fetch list excludes those placeholders.
Practical Debug Checklist
When this error appears:
- Identify tensor named in error message.
- Search where it enters fetch list.
- Search where it enters feed dictionary.
- Inspect wrapper functions that compose run arguments.
- Add assertion guard and rerun.
This approach finds root cause faster than random graph edits.
Common Pitfalls
- Building feed and fetch collections in mutable shared structures.
- Passing placeholders through generic output lists.
- Mixing TensorFlow 1 graph wrappers with TensorFlow 2 style code.
- Reusing variable names that hide tensor role boundaries.
- Debugging only failing call site and not wrapper layers.
Summary
- The error means one tensor is used as both input and output in one run.
- Keep placeholders in feeds and computed tensors in fetches.
- Refactor generic wrappers into explicit run interfaces.
- Add runtime guards in legacy code to catch overlap early.
- Prefer modern TensorFlow execution models when migration is possible.

