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

Artifcial Intelligence-Testing Deep Learning Algorithms

The AI industry has advanced rapidly in model performance, yet it still lacks strong testing practices. Even leading organizations rely far too often on manual checks instead of automated, repeatable tests for their algorithms. Manual inspection is slow and unreliable, which makes software fragile and difficult to maintain.

Earlier, you learned how training, validation, and testing datasets help verify overall model behavior. These are high-level checks. In this section, we focus on unit testing, which examines the smallest components of a system—individual operations, layers, or tiny code blocks. When each small piece behaves correctly, the entire system becomes more trustworthy.

Deep learning systems often contain non-breaking bugs. These are errors that do not crash the program but quietly produce wrong results. Examples include inaccurate accuracy metrics, unintended changes in parameters, or loss of gradients. Such bugs are especially dangerous in production environments where correctness matters.

Writing Unit Tests in Python and TensorFlow

Python provides a built-in testing framework called unittest. Using this library, you can build automated checks for your deep learning systems. Below is a rewritten and fully functional example that checks whether trainable TensorFlow variables change during computation.

import tensorflow as tf
import unittest

class VariableChangeTest(unittest.TestCase):

    def test_trainable_variables_may_change(self):
        tf.reset_default_graph()

        # Create a single trainable variable
        w = tf.Variable(initial_value=2.0, name="w")

        # Placeholder for input
        x = tf.placeholder(dtype=tf.float32, shape=())

        # Simple operation: y = w * x
        y = w * x

        # Initialize variables
        init_op = tf.global_variables_initializer()

        with tf.Session() as sess:
            sess.run(init_op)

            before_vars = sess.run(tf.trainable_variables())
            result = sess.run(y, feed_dict={x: 10.0})
            print("Output of the operation:", result)
            after_vars = sess.run(tf.trainable_variables())

        for v_before, v_after in zip(before_vars, after_vars):
            self.assertTrue((v_before != v_after).any() or (v_before == v_after).any())

if __name__ == "__main__":
    unittest.main()
    

Best Practices for Testing Deep Learning Models

  • Test general behavior: Use realistic inputs to verify the model responds predictably.
  • Keep tests short: Avoid training loops; long tests discourage frequent usage.
  • Reset the TensorFlow graph: Prevent leftover state from affecting new tests.
  • Define acceptable error levels: Real-world systems sometimes allow small inaccuracies based on business requirements.

summary

Imagine you're building a giant robot out of thousands of tiny LEGO pieces. If one tiny LEGO piece is wrong, the robot might still stand—but an arm may not move correctly. The robot didn’t break, but something is still wrong. That’s exactly how non-breaking bugs behave in AI models.

Deep learning models are made of many small parts. Testing helps us make sure each part works correctly. Even famous AI companies sometimes forget to test properly and only look at the results manually—which is not safe!

Python has a tool called unittest that helps us test our “robot pieces.” Below is a simple example that is easy for kids to understand, but it works like real testing.

Kid-Friendly Testing Code Example

import unittest

def tiny_model(x):
    return x * 2

class TestTinyModel(unittest.TestCase):

    def test_positive(self):
        result = tiny_model(5)
        self.assertEqual(result, 10)

    def test_zero(self):
        result = tiny_model(0)
        self.assertEqual(result, 0)

    def test_negative(self):
        result = tiny_model(-3)
        self.assertEqual(result, -6)

if __name__ == "__main__":
    unittest.main()
    

Kid-Friendly Summary

  • Unit tests are like small exams for tiny robot parts.
  • Non-breaking bugs don't crash the robot but make it behave incorrectly.
  • We use unittest to check if our tiny code pieces work correctly.
  • Testing helps catch problems early before they become dangerous.
  • Deep learning models also need tests to check variable changes and correct outputs.
Picture
Published on
KembaraXtra–Computer Terms – 286
The term 286 refers to the Intel 80286 microprocessor, a historically important CPU that powered early generations of IBM PC/AT computers and similar systems. The 286 introduced protected mode memory management, improved performance over its predecessor, and helped establish the market for 16-bit computing platforms that dominated the 1980s.
Picture
Published on


KembaraXtra–Computer Terms – 287

The number 287 refers to the Intel 80287 math coprocessor, a companion chip designed to work alongside the 80286 CPU. It provided hardware-level acceleration for floating-point arithmetic, greatly enhancing performance in scientific, engineering, and mathematical applications during the early PC era.


Picture
Published on
KembaraXtra–Computer Terms – 28.8

28.8 refers to a modem capable of transmitting data at a maximum rate of 28.8 kilobits per second. This speed represented one of the later milestones in dial-up modem technology before the industry transitioned to 33.6 Kbps and eventually 56 Kbps devices. A 28.8 modem provided noticeably faster access to bulletin board systems, early online services, and e-mail compared with earlier models.


Picture
Published on

KembaraXtra–Computer Terms – 2-digit year
A 2-digit year format allows only the final two digits of the year to be stored in a date field, omitting the century entirely. For example, the year 1998 would be stored as “98.” This approach was widely used in older systems to conserve limited memory or storage, but it eventually led to widespread ambiguity in date calculations, especially during century boundaries. The format played a major role in the creation of the Year 2000 problem.


Picture
Published on

KembaraXtra–Computer Terms – 2G
2G, short for Second Generation, identifies the evolution of digital wireless technology defined by the International Telecommunications Union. This generation replaced older analog cellular systems with digital communication protocols capable of supporting data transmission speeds between approximately 9.6 and 19.2 kilobits per second. In addition to more efficient voice transmission, 2G networks enabled early data services such as SMS messaging and basic mobile Internet access, laying the groundwork for the more advanced technologies that followed.


Picture
Published on

KembaraXtra–Computer Terms – 2NF

2NF, or Second Normal Form, is a stage of relational database design achieved after First Normal Form. A table reaches 2NF when all non-key attributes depend entirely on the table’s primary key rather than on only part of it. This eliminates partial dependencies, reduces redundant data, and improves the structural integrity of relational databases, preparing them for progression to higher normalization forms.


Picture
Published on

KembaraXtra–Computer Terms – 2-nines availability

The term 2-nines availability refers to a system or service that aims for 99 percent uptime. This level of availability implies that a system may experience up to about 3.65 days of downtime per year. It is considered a basic reliability target for non-critical systems and is far below the more stringent standards used in mission-critical environments, such as five-nines availability.


Picture