TECHNOLOGY 

Published on
Artificial Intelligence – Scaling Out with Distributed TensorFlow

As machine learning models grow larger and require more computation, a single machine—or even a single GPU—may not be powerful enough to train them efficiently. To overcome this limitation, TensorFlow provides mechanisms to distribute training across multiple machines or devices, allowing us to scale out our compute resources.

Although several distributed frameworks exist—native Distributed TensorFlow, TensorFlowOnSpark, and Horovod—this section focuses exclusively on native Distributed TensorFlow, which is built directly into TensorFlow’s core design.

Approaches to Distributed Training

In distributed systems, there are two main strategies for dividing the workload: model parallelism and data parallelism.

Picture
Model parallelism splits different parts of the model across multiple devices.

  • Device A handles one portion of the model
  • Device B handles another portion
  • Together they complete forward and backward passes

This method is most useful when the model is too large to fit onto a single GPU, or when you have a large number of compute nodes that you want to utilize simultaneously.


Picture
Data parallelism replicates the entire model on each device.
Each device receives a different piece of the training data, computes gradients, and then sends them to be combined.​
  • Works best when you have fewer nodes
  • More common than model parallelism
  • Easy to scale and widely supported in TensorFlow
After devices complete their work, a central entity aggregates the results.


Picture
When performing data parallelism in TensorFlow, training relies on a key component known as the parameter server (PS).

Parameter Server Responsibilities

  • Stores the master copy of model weights and variables
  • Aggregates gradients sent from workers
  • Applies updates and broadcasts updated parameters back
Parameter servers typically run on CPUs.

Worker Nodes (TensorFlow Servers)

  • Typically run on GPUs
  • Perform forward/backward computations
  • Send gradients to the parameter server
Among these workers, one is designated as the chief worker, which is responsible for:

  • Initializing variables
  • Coordinating training steps
  • Saving checkpoints
  • Managing the training session

Together, the parameter servers and workers form a TensorFlow cluster.


Picture


Synchronous vs. Asynchronous Updates

​
Distributed training can share gradients and update the model in two different ways: synchronously or asynchronously.

Synchronous Distribution

All workers operate in lockstep.


  • Every worker receives its data at the same time
  • Every worker computes gradients
  • Workers wait at a barrier until all results are ready
  • Only then is the model updated

Pros:
  • More stable updates (similar to large-batch SGD)

Cons:
  • Slowest worker (straggler) delays everyone
  • Can significantly reduce throughput

Asynchronous Distribution

Workers operate independently, without waiting.


  • Each worker trains at its own speed
  • Gradients are sent to the parameter server immediately
  • The PS updates the model as soon as gradients arrive

Pros:

  • Fast and efficient
  • No worker-to-worker waiting

Cons:

  • Workers may use older parameter versions
  • Updates are noisier

SGD Behavior in Distributed Training


Stochastic Gradient Descent (SGD) normally works in a loop:


  1. Compute gradients
  2. Update model weights
  3. Repeat

In distributed training:


  • Synchronous SGD = all gradients collected → update once per iteration
  • Asynchronous SGD = each gradient applied immediately, leading to many small updates

This changes training dynamics and may affect convergence stability, depending on the method used.

Preparing Code for Distributed TensorFlow

Building a distributed TensorFlow program involves three main steps:

1. Define the Cluster


Use tf.train.ClusterSpec and tf.train.Server to describe:

  • Parameter servers
  • Worker servers
  • Network addresses
  • Roles of each machine

2. Assign Devices with tf.device()

Explicitly place:


  • Variables on parameter servers
  • Computation operations on worker GPUs

This ensures TensorFlow knows exactly where to run each operation.


3. Use MonitoredTrainingSession

Replace a standard session with:


  • tf.train.MonitoredTrainingSession()

This automatically handles:


  • Initialization
  • Recovery from failures
  • Checkpointing
  • Synchronization between chief and workers

This makes distributed training more robust and easier to manage.


Summary

Why do we “scale out”?


Imagine you have a huge pile of homework and only one pencil—you’ll finish very slowly.
But if ten friends help you, you’ll finish much faster.
Distributed TensorFlow is like that: many computers helping train one big model.

Two Ways to Share the Work

Model Parallelism

Everyone works on different parts of the project.

Data Parallelism

Everyone works on the same project, but with different pages of homework (different data).

What’s the Parameter Server?

It’s like the team leader:


  • Collects everyone’s answers
  • Decides the final version
  • Sends the new version to the whole team
Synchronous vs. Asynchronous


🟦 Synchronous = “Wait for everyone!”

Nobody moves forward until everyone finishes a task.


🟩 Asynchronous = “Go at your own speed!”

You send your work when you’re done, without waiting.





Published on
Artificial Intelligence – Testing and Maintaining Your Applications

Building AI systems—whether they learn continuously from new data (online learning) or are trained once and used afterward (offline learning)—requires more than just creating a model. It also requires ongoing testing and maintenance to make sure everything keeps working the way it should. No matter how the model learns, we must establish reliable monitoring systems and safety checks that alert us whenever the model’s predictions or its essential infrastructure start acting unexpectedly.

Expanded Explanation

In traditional software development, testing is relatively straightforward: for each specific input, we know exactly what the output should be. This makes it easy to write tests that verify whether the system behaves correctly.

Machine learning, however, doesn’t follow that neat pattern. A model may produce different outputs for inputs that look similar, and those outputs depend on many factors—training data, randomness, environment, even hardware differences. This makes classic, rule-based testing harder to apply.

Despite these challenges, testing remains crucial. In machine learning projects, “testing” involves carefully verifying the following:
  • Inputs: Are we providing the model with data in the right format and within expected ranges?
  • Outputs: Are the predictions reasonable, consistent, and within acceptable boundaries?
  • Errors: Are we handling failures, missing data, or unexpected behaviors safely?

In this chapter, we will explore practical methods for testing machine learning code, including strategies tailored for systems that behave unpredictably. We’ll also go through best practices that help ensure reliability even when perfect reproducibility isn’t possible.

Keeping AI Applications Healthy After Deployment

Once an AI model is released into the real world, the job isn’t over. Models may degrade over time as the world changes—a phenomenon known as model drift. To keep the system stable, AI applications must be continuously monitored and maintained.

DevOps tools, such as Jenkins, play an important role here. They can automatically run a set of tests every time a new version of a model or application component is created. Only if all tests pass will the updated version be allowed to move into production. This reduces the risk of shipping broken or unsafe updates.

While we do not expect machine learning engineers to design full development or deployment pipelines on their own, it is important to understand the key principles behind them. These concepts help you collaborate effectively with DevOps teams and ensure that your models are safely and efficiently deployed.



What This All Means?

Imagine you built a robot that gives you advice—maybe it helps with homework or tells you what game to play. To make sure your robot stays helpful and doesn’t start acting weird, you need to check on it regularly.

Testing

Testing is like asking the robot:
  • “Are you listening correctly?”
  • “Are you answering in a way that makes sense?”
  • “Are you freezing or making mistakes?”

In regular computer programs, the answer is the same every time, so it’s easy to test. But with AI robots, they might give different answers because they learn from data. That makes testing trickier!

Maintaining

After your robot is built, you still need to watch it. Maybe it starts learning things that are wrong or confuses new information. So you check it from time to time and fix things if needed.

Tools like Jenkins are like helpers that test the robot every time you teach it something new. If the robot starts making mistakes, the helper won’t let those mistakes go into the real world.

So basically:
  • Testing: making sure your AI works properly.
  • Maintaining: keeping it working even as things change.
Picture