Dp-sgd-mnist error when running server.py


When I try to run the dp-sgd-mnist example i get an error here:

ImportError: cannot import name ‘estimator_training’ from ‘tensorflow.python.distribute’ (C:\git_repos\FlwrNightly\lib\site-packages\tensorflow\python\distribute_init_.py)

This seems to be a dependency thing with tensorflow_estimator. I get the same behaviour with python 9 and python 11. Both of these attempts were in a new venv, and nothing installed except the requirements.txt in the dp-sgd-mnist folder.

My flower version is 1.7.0
my tensorflow_estimator version is: 2.15.0

1 Like

Hi Ruairi, welcome to Flower Discuss :wave:

Could you check if the other imports can be imported? That might help us understand if it’s a general import issue, or something with that particular dependency.

In addition to that, we often recommend using WSL2 on Windows.


Hi Daniel, thanks for the answer.

Just as a quick note, I have a computer with Ubuntu 22.04 on it. I tried the full steps there with python 10 and got the same behaviour.

The issue seems to be caused by tensorflow 2.16.1, where estimator was removed. It is mentioned in the release notes here: Releases · tensorflow/tensorflow · GitHub. I have tried downgrading to a number of different tensorflow versions now and all have an issue somewhere. What version of tensorflow should I be using. It could also be caused by tensorflow-privacy which is version 0.8.10 or tensorflow-probability which is version 0.20.1 .

I’m a relative beginner in this type of thing, so I’m not sure how else i can try to resolve these dependency issues. Thanks for your help :slight_smile:


I got this solved in the end by upgrading tensorflow-privacy to version 0.9.0 and reworking the calculate_epsilon function as shown here. This was based on the updated code in

def compute_epsilon(
    epochs: int, num_train_examples: int, batch_size: int, noise_multiplier: float
) -> float:
    """Computes epsilon value for given hyperparameters.

    Based on
    if noise_multiplier == 0.0:
        return float("inf")
    steps = epochs * num_train_examples // batch_size
    orders = [1 + x / 10.0 for x in range(1, 100)] + list(range(12, 64))
    accountant = dp_accounting.rdp.RdpAccountant(orders)
    sampling_probability = batch_size / num_train_examples
    event = dp_accounting.SelfComposedDpEvent(
            sampling_probability, dp_accounting.GaussianDpEvent(noise_multiplier)


    # Delta is set to approximate 1 / (number of training points).
    return accountant.get_epsilon(target_delta=1e-4)
1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.