TensorFlow Federated How to tune non-IIDness in federated dataset?
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
In federated learning, "tuning non-IIDness" usually means controlling how different each client's local data distribution is from the global distribution. In TensorFlow Federated experiments, the usual way to do this is not through a single built-in slider. It is through how you partition the dataset across simulated clients.
What Non-IIDness Means In Practice
A federated dataset becomes more non-IID when different clients see systematically different samples. That can happen in several ways:
- label skew, where each client sees only a few classes
- quantity skew, where some clients have much more data than others
- feature skew, where input distributions differ by client
- concept skew, where the label meaning or decision boundary differs across clients
For most simulation work, label skew is the easiest non-IID pattern to control deliberately.
The Most Common Knob: Dirichlet Partitioning
A standard way to tune label skew is to sample each class distribution across clients from a Dirichlet distribution.
The key parameter is usually called alpha:
- small
alphameans more non-IID, because each class concentrates on fewer clients - large
alphameans more IID-like, because class data spreads more evenly
A small standalone example makes the idea concrete.
This does not use TFF directly, but it shows the partitioning logic that is usually applied before building federated client datasets.
Turning Partitions Into TFF Client Data
Once you have per-client indices, you can slice the original dataset and build one dataset per client.
The important point is that non-IIDness is expressed through client membership, not through some special TFF optimizer flag.
Other Useful Non-IID Controls
Number Of Classes Per Client
A simple alternative is to give each client only k labels.
For example, in a 10-class task:
- '
k = 10is close to IID' - '
k = 2is strongly label-skewed' - '
k = 1is extremely non-IID'
This is a common benchmark style because it is easy to explain and reproduce.
Client Sample Counts
You can also vary how much data each client has. Even with the same label mix, unequal client sizes change training dynamics and aggregation behavior.
Preprocessing Differences
Some experiments introduce client-specific noise, resolution changes, or feature transforms to simulate device heterogeneity. That is another form of non-IIDness, but it should be introduced deliberately because it changes the interpretation of the results.
What To Tune Alongside The Data Split
As non-IIDness increases, model training usually becomes less stable. So the partitioning strategy should be tuned together with training hyperparameters such as:
- local epochs
- client learning rate
- server learning rate
- client sampling rate
- regularization or proximal terms
If you increase skew without adjusting training, you may confuse a training-instability problem with a data-partitioning problem.
Common Pitfalls
A common mistake is looking for a TensorFlow Federated API argument called something like non_iid_level. In practice, the non-IIDness comes from how you construct client datasets.
Another issue is changing several skew factors at once and then losing track of what caused the result. Tune one dimension at a time, such as Dirichlet alpha or labels-per-client.
Developers also sometimes compare experiments with different client counts, data volumes, and skew settings all at once. That makes the results hard to interpret.
Finally, do not assume stronger non-IIDness is always more realistic. Real-world heterogeneity depends on the application, so the partitioning scheme should match the phenomenon you are trying to study.
Summary
- In TFF experiments, non-IIDness is usually tuned by how data is partitioned across clients.
- Dirichlet partitioning is a common way to control label skew with one parameter,
alpha. - Smaller
alphavalues produce more non-IID client datasets. - You can also tune non-IIDness with labels-per-client, unequal client sizes, or client-specific preprocessing.
- Interpret partitioning changes together with training hyperparameters, not in isolation.

