Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ValueError: Dimension size must be evenly divisible by 250 but is 1 for '{{node Reshape}} #287

Open
codebecker opened this issue Jul 25, 2022 · 3 comments

Comments

@codebecker
Copy link

Hello Community,

I'm currently working on a project which requires me to include differential privacy. While I try to implement it using tf privacy, I become an error message:

ValueError: Dimension size must be evenly divisible by 250 but is 1 for '{{node Reshape}} = Reshape[T=DT_FLOAT, Tshape=DT_INT32](sparse_categorical_crossentropy/weighted_loss/value, Reshape/shape)' with input shapes: [], [2] and with input tensors computed as partial shapes: input[1] = [250,?].

The error takes place in line 381 where the model should be fitted. Because my code is over 400 lines long and I have no clue which lines are interesting, I will share it with you via codeshare: https://codeshare.io/mpvkVj

If the issue gets resolved, I will include the interesting lines later on. Thank you very much for every hint 😃

@NamOhSeung
Copy link

NamOhSeung commented Dec 14, 2022

@codebecker If you have solved this problem, can you tell me how you solved it?

@codebecker
Copy link
Author

codebecker commented Dec 18, 2022

TLDR: The error appear because The number of microbatches should evenly divide the batch size which did not work out in my case so I set the microbatches parameter to 1 to avoid this error to the cost of performance.

I used a batch size of 250 which yield the error of Dimension size must be evenly divisible by 250 because the batch size was not dividable by 250. However I changed the number of training images to 5000 and the batch size to 500 which should have clearly fixed this issue but the error still continues to appear. I am not sure if the error source is in my code or the implementation (as my changes should have fixed it) however I found a "workaround" which is to set the parameter of microbatches to 1. As described in the cited explanation of the microbatches from the offical implementation example this is the default setting but comes with a higher cost of performance.

microbatches (int) - Each batch of data is split in smaller units called microbatches. By default, each microbatch should contain a single training example. This allows us to clip gradients on a per-example basis rather than after they have been averaged across the minibatch. This in turn decreases the (negative) effect of clipping on signal found in the gradient and typically maximizes utility. However, computational overhead can be reduced by increasing the size of microbatches to include more than one training examples. The average gradient across these multiple training examples is then clipped. The total number of examples consumed in a batch, i.e., one step of gradient descent, remains the same. The number of microbatches should evenly divide the batch size.

@NOS9512: I hope that helps wish you a merry christmas 🎄

@Nada-Bu
Copy link

Nada-Bu commented Mar 12, 2023

I faced a similar problem and training is very slow with the microbtach set to 1

Any update to make training possible with a bigger size of the microbatch?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants