PyTorch vs TensorFlow: which should beginners learn first?
Our advice: learn PyTorch first, unless your course, team or project uses TensorFlow. See the same model in both, a side-by-side table and a decision rule.
Should you learn PyTorch or TensorFlow first? For most beginners, our answer is PyTorch, unless you already have a reason to use TensorFlow. PyTorch shows every step of training in plain Python, which is the clearest way to learn how deep learning works, and those ideas carry straight over to TensorFlow later. Choose TensorFlow with Keras first if your course, team or project already uses it.
This is an editorial recommendation for learners, not a speed benchmark or a ranking of employer demand. Both frameworks are capable and both are widely used. Tensors, gradients, layers, loss functions and optimizers work the same way in each, so learning the second framework mostly means learning new names for steps you already understand.
Should I learn PyTorch or TensorFlow first? A decision rule
| Your situation | Start with | Why |
|---|---|---|
| You want to understand how training works | PyTorch | The training loop is yours to write, so every step is visible |
| Your course, tutorial or team uses TensorFlow and Keras | TensorFlow with Keras | Finishing one maintained path teaches more than switching halfway |
| You will work with Hugging Face Transformers models | PyTorch | Transformers v5 made PyTorch its only backend |
| You will contribute to an existing repository | Its framework | Reproduce its environment and evaluation before changing anything |
| You want the shortest path to a first working model | Keras, on TensorFlow or PyTorch | compile and fit run the training loop for you, and Keras 3 runs on either framework |
| You want to run models in a web browser | TensorFlow, with TensorFlow.js | TensorFlow.js trains and runs models in JavaScript, in the browser or Node.js |
| You are on native Windows and want to train on an NVIDIA GPU | PyTorch, or TensorFlow inside WSL2 | TensorFlow 2.10 was the last release with GPU support on native Windows |
If none of these applies, start with PyTorch. SchoolWhool's Deep Learning course teaches neural networks in PyTorch, and its lessons open as they are released.
PyTorch vs TensorFlow at a glance
| PyTorch | TensorFlow | |
|---|---|---|
| Origin | Started at Meta (then Facebook); now run by the PyTorch Foundation | |
| High-level API | nn.Module for models; you write the loop, or add a library | Keras is built in: compile, fit, evaluate |
| Training loop | Usually written by you, four lines per batch | model.fit, or a custom loop with tf.GradientTape |
| How code runs | Eagerly, line by line; torch.compile speeds it up | Eagerly by default; tf.function compiles it into a graph |
| Debugging | Ordinary Python debugger and print | The same in eager mode; harder inside a compiled tf.function |
| Deployment tools | torch.export, ExecuTorch for devices, ONNX export | TensorFlow Serving, TensorFlow.js, LiteRT for devices |
| Keras 3 | Supported as a Keras backend | The default Keras backend |
Deployment is less of a dividing line than it was: LiteRT, Google's on-device runtime built on TensorFlow Lite, now converts PyTorch and JAX models as well as TensorFlow ones.
PyTorch vs TensorFlow for beginners: the same model in both
Here is one small task in each framework: classify 1,000 random points by whether x1 + x2 > 0, training on 800 and checking accuracy on the other 200. Both use the same network (2 inputs, 16 hidden units, 1 output), the Adam optimizer, batches of 32 and 20 epochs.
PyTorch, with the training loop written out:
import torch
from torch import nn
from torch.utils.data import DataLoader, TensorDataset
torch.manual_seed(0)
X = torch.randn(1000, 2)
y = (X[:, 0] + X[:, 1] > 0).float().unsqueeze(1) # label: 1 if x1 + x2 > 0
train = DataLoader(TensorDataset(X[:800], y[:800]), batch_size=32, shuffle=True)
model = nn.Sequential(nn.Linear(2, 16), nn.ReLU(), nn.Linear(16, 1))
loss_fn = nn.BCEWithLogitsLoss()
optimizer = torch.optim.Adam(model.parameters(), lr=0.01)
for epoch in range(20):
model.train()
for X_batch, y_batch in train:
loss = loss_fn(model(X_batch), y_batch) # forward pass and loss
optimizer.zero_grad() # clear the last batch's gradients
loss.backward() # compute new gradients
optimizer.step() # update the weights
model.eval()
with torch.no_grad():
logits = model(X[800:])
accuracy = ((logits > 0).float() == y[800:]).float().mean()
print(f"validation accuracy: {accuracy.item():.3f}")
TensorFlow with Keras, where fit runs the loop:
import keras
import numpy as np
rng = np.random.default_rng(0)
X = rng.normal(size=(1000, 2)).astype("float32")
y = (X[:, 0] + X[:, 1] > 0).astype("float32") # label: 1 if x1 + x2 > 0
model = keras.Sequential([
keras.Input(shape=(2,)),
keras.layers.Dense(16, activation="relu"),
keras.layers.Dense(1, activation="sigmoid"),
])
model.compile(
optimizer=keras.optimizers.Adam(learning_rate=0.01),
loss="binary_crossentropy",
metrics=["accuracy"],
)
model.fit(X[:800], y[:800], batch_size=32, epochs=20, verbose=0)
loss, accuracy = model.evaluate(X[800:], y[800:], verbose=0)
print(f"validation accuracy: {accuracy:.3f}")
Both printed validation accuracy: 0.995 when we ran them with PyTorch 2.15 and with TensorFlow 2.21 and Keras 3.15. The Keras version runs on TensorFlow by default; set the KERAS_BACKEND environment variable to torch and the same code runs on PyTorch.
The difference is what you see. In PyTorch, the four lines inside the batch loop are the whole of training: predict and measure the loss, clear old gradients, compute new ones, take a step. Keras does exactly that inside fit. PyTorch also asks you to switch modes yourself with model.train(), model.eval() and torch.no_grad(), which PyTorch train, eval and no_grad explains. A small detail: the PyTorch model outputs raw scores and its loss applies the sigmoid, while the Keras model ends in a sigmoid layer. Both are the usual style in each framework.
What are PyTorch, TensorFlow and Keras?
PyTorch and TensorFlow provide tools for tensor computation, automatic differentiation and building models. Their official beginner material demonstrates complete training workflows, including evaluating and saving models: PyTorch Learn the Basics and TensorFlow's Keras overview.
Keras is a high-level API. A beginner often meets it through a TensorFlow tutorial, but Keras 3 also supports TensorFlow, JAX and PyTorch backends, as its official overview explains. Treating Keras as permanently synonymous with TensorFlow makes modern comparisons confusing.
When someone says they are using Keras, ask which backend and version their project uses. Follow that project's setup instructions rather than mixing imports from unrelated tutorials.
What an explicit training loop helps you understand
A training loop makes the repeated operations visible: read a batch, produce predictions, calculate loss, calculate gradients and update parameters. Then evaluate on held-out data without using it to update the model.
PyTorch's optimization tutorial walks through these operations. It is a useful route if you want to pause at each step and inspect what changes.
For a learning exercise, write down what each variable represents before running the loop. What is the input shape? What does one label mean? Which parameters are updated? Where is the learning rate used? What is saved when you save a model?
Start with Shape, dtype and Reshaping, then vectorised operations and broadcasting. Study gradient descent so the parameter update has a meaning beyond “the next line of code.”
What a high-level training workflow helps you practise
Keras lets you configure a model's training behaviour and use methods such as fit and evaluate. This can make a first experiment compact, leaving you more room to focus on the dataset and evaluation design. TensorFlow's beginner quickstart provides one example.
High-level methods still require you to understand what you supply. A loss measures the training objective; a metric reports a quantity you want to monitor. Those may be different. Read cross-entropy and log loss before treating a decreasing loss as proof that a classifier meets your goal.
Use the fit, predict and transform lesson to establish the distinction between fitting and using a model. It teaches the scikit-learn API, rather than either deep learning framework, but the separation is helpful preparation.
Is one framework faster, easier or better for jobs?
A meaningful speed comparison fixes the model, hardware, input shapes, precision, software versions and measurement method. A timing result from someone else's workload does not settle your project. This article does not make a performance claim.
Ease also depends on what you already know. If a maintained notebook explains exactly the task you want to solve, finishing that notebook can be more useful than switching because of a broad framework preference.
For jobs, read the postings for the roles you want and note which framework each one names. A project you can explain end to end in one framework shows the concepts both depend on, and the second framework is quicker to pick up once you have them.
A fair exercise for choosing between them
If you are still undecided, try this small comparison. It is a suggested learning exercise, not a benchmark SchoolWhool has run.
- Pick one classification task with clear labels and permission to use the data.
- Keep its training, validation and test examples fixed across both implementations.
- Follow an official beginner tutorial in each framework, adapting only what the task needs.
- Save and reload each model. Check that the reloaded model can make predictions on the same inputs.
- Write down which workflow you can debug and explain more confidently.
Compare what you learned. Different initializations and implementation details can produce different metrics; do not declare a framework winner from one small run.
For a stronger project, add a simple baseline and an error review. The portfolio project briefs explain what evidence belongs beside the model. When adapting an image model, read transfer learning vs fine-tuning before deciding which weights to update.
Common questions
Should I learn both PyTorch and TensorFlow at the same time?
For a first project, our recommendation is to finish one complete workflow in one framework. Move to the other once you can prepare data, train, validate, save, reload and explain the first model.
Is PyTorch easier than TensorFlow for beginners?
It depends on what "easier" means. Keras gets a first model running in fewer lines, as the example above shows. PyTorch makes each step of training visible, which is easier to debug and to learn from. That is why we suggest PyTorch first for understanding, and Keras when you want a quick first result.
Is TensorFlow still worth learning?
Yes, if your course, team or deployment target uses it. TensorFlow is still released and maintained, Keras 3 runs on it by default, and TensorFlow.js and TensorFlow Serving are built around it. If you have no such reason, learn PyTorch first and pick up TensorFlow when a project needs it.
Is TensorFlow the same as Keras?
No. TensorFlow is a framework; Keras is a high-level API with multiple supported backends in Keras 3. The backend and version matter when you reproduce an example.
Can I start without a GPU?
Yes. Both examples above finish in a few seconds on an ordinary CPU, and so do most beginner exercises with small datasets. Larger image or language models need a GPU; free notebook services such as Google Colab offer limited GPU time for learning. Avoid buying hardware before measuring the task you actually want to run.
Lessons to study before your first training loop
Use defining functions to organize repeatable code and uv, packages and environments to keep project dependencies separate. Continue through the Data Tools track and the Machine Learning track for the concepts both frameworks depend on. If neural networks are new to you, read what a neural network is first, and find more worked examples in the PyTorch resources.
Not sure you need a deep learning framework yet? Deep learning vs machine learning explains when a classical model is enough, and how to learn AI from scratch shows where a framework fits in a 12-week plan.
Framework references were checked on 29 October 2026. Follow their current installation guides for your operating system.