How do I set up TensorFlow in the Google cloud?
ML System Design practice on Codemia
Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.
Introduction
Setting up TensorFlow on Google Cloud usually means choosing where you want the code to run, then creating a clean Python environment with the right TensorFlow build. For many teams the simplest path is a Compute Engine VM or a managed notebook environment, because both let you control the machine type while keeping the TensorFlow installation process familiar.
Choose The Right Google Cloud Service First
There is no single "Google Cloud TensorFlow" button. The usual options are:
- a Compute Engine VM for maximum control
- a managed notebook or workbench environment for interactive work
- containerized deployment on GKE for larger platform setups
If your goal is just to develop and train a model, a VM or notebook instance is usually the fastest way to get started.
Create A Compute Engine VM
A straightforward setup is a Linux VM with enough CPU, RAM, and optional GPU support for your workload.
If you need GPU training, choose a GPU-compatible machine and make sure your project has GPU quota in the selected region.
Connect And Build A Clean Python Environment
Once connected, create a virtual environment and install TensorFlow.
That gives you an isolated environment without polluting the system Python installation.
Verify The Installation
On a CPU-only machine, you should at least see a CPU device. On a GPU-enabled setup, verifying the GPU depends on the driver and runtime stack being installed correctly.
GPU Setups Need Extra Steps
Installing TensorFlow on a GPU VM is not just a pip install problem. The machine also needs the correct driver and supporting runtime components for the TensorFlow build you chose.
That is why many teams prefer either:
- Google-provided deep learning VM images
- managed notebook images with ML libraries preinstalled
Those images reduce the amount of manual GPU driver setup you need to do yourself.
Store Code And Data Deliberately
Do not treat the VM boot disk as your long-term data lake. A practical pattern is:
- keep code in Git
- store datasets and model artifacts in Cloud Storage
- mount or download only what the current job needs
For example, copying artifacts to a bucket is simple:
This keeps compute and storage concerns separate.
Notebooks Are Fine For Exploration
If your main goal is experimentation, a managed notebook instance is often easier than a manually configured VM. The core ideas stay the same: choose a machine type, open the notebook, create an environment if needed, and verify TensorFlow sees the hardware you expect.
The tradeoff is control versus convenience. VMs expose more of the underlying machine; notebooks reduce setup work.
Security And Cost Still Matter
Even for a quick ML environment, basic operational hygiene matters:
- restrict SSH exposure
- stop or delete idle instances
- use least-privilege IAM
- avoid storing secrets directly in notebooks or source files
TensorFlow training instances can become expensive quickly, especially with GPUs, so lifecycle discipline matters.
Common Pitfalls
The most common mistake is treating Google Cloud as if it automatically solves environment compatibility. You still need the right Python version and TensorFlow build. Another is choosing a GPU VM without the supporting driver stack and then wondering why TensorFlow only sees the CPU. Developers also often leave expensive instances running after experiments end. Finally, storing all data and models only on the VM disk makes the setup fragile and hard to reproduce.
Summary
- The simplest TensorFlow setup on Google Cloud is usually a VM or managed notebook.
- Use a clean virtual environment and install TensorFlow there.
- Verify the runtime with
tf.config.list_physical_devices(). - GPU setups need the full supporting runtime, not just the Python package.
- Keep code, data, and compute concerns separated so the environment stays reproducible.
Related reading
- How do I shape my input data for use with Conv1D in keras?
- How do I specify the model_config_file variable to tensorflow-serving in docker-compose?
- How do I split Tensorflow datasets?
- How do I start tensorflow docker jupyter notebook
- How do I solve overfitting in random forest of Python sklearn?
- How do I store a fitted PCA so that I may transpose unseen testing dataset? I do not wish to keep the large training dataset on my CPU
- How do I specify template parameters when running AWS SAM Local?
- How do I ssh to nodes in ACS Kubernetes cluster?

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
ML System Design practice on Codemia
Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.