Install any skill in seconds. Free to start, no credit card required.
Get Started Free →brycewang-stanford/tensorflow-guide
TensorFlow best practices for tf.function, GPU memory, and deployment
Passed 24 of 24 test cases with the skill, and 23 of 24 without it.
1 fixed23 passed either way0 still failing0 broke
Tokens, turns and time describe resource use, not a dollar price.
A test case the skill fixed. Same model, same prompt, with and without the skill.
When training a model on a single machine containing four NVIDIA GPUs, which synchronous distribution strategy should be initialized, and how should the global learning rate be scaled relative to the per-replica batch size?
| Checked | Without skill | With skill |
|---|---|---|
| Recommends using tf.distribute.MirroredStrategy for single-node multi-GPU training. | Passed | Passed |
| Recommends scaling the learning rate by multiplying by strategy.num_replicas_in_sync. | Missed | Passed |
The instructions your model reads when the skill loads.
TensorFlow is a production-grade machine learning framework that excels at deployment, distributed training, and hardware acceleration. While PyTorch dominates pure research prototyping, TensorFlow remains the standard in industry ML systems and is heavily used in applied research where models must move from experiment to production.
TensorFlow 2.x unified eager execution with graph-mode performance through tf.function, but this hybrid approach introduces subtle pitfalls. Understanding when and how TensorFlow traces functions, manages GPU memory, and distributes computation is essential for writing correct and efficient code.
This guide covers the key patterns that trip up researchers: tf.function tracing semantics, GPU memory management, distributed strategies, model export, and the ecosystem of tools (TFX, TensorBoard, TF Serving) that make TensorFlow uniquely powerful for end-to-end ML workflows.
import tensorflow as tf
@tf.function
def add(a, b):
print("Tracing!") # Runs only during tracing, NOT every call
tf.print("Executing!") # Runs every call (TF op)
return a + b
# First call with float32 shape (2,) -- traces
add(tf.constant([1.0, 2.0]), tf.constant([3.0, 4.0])) # Prints "Tracing!" + "Executing!"
# Second call with same signature -- reuses trace
add(tf.constant([5.0, 6.0]), tf.constant([7.0, 8.0])) # Prints only "Executing!"
# Third call with different dtype -- re-traces!
add(tf.constant([1, 2]), tf.constant([3, 4])) # Prints "Tracing!" + "Executing!"
# PITFALL 1: Python side effects in tf.function
counter = 0
@tf.function
test cases passed, vs 23 / 24 without
More skills from the same source and nearby in the registry, with their headline benchmark lift.