-
Notifications
You must be signed in to change notification settings - Fork 3
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
Used hardware PRNG for dropout #26
Conversation
It seems the PRNG is very crude (as long as my code is correct). I created a test that uses a vector of size 131072 and applied differing probabilities for dropout.
Half the time the dropout rate deviated quite a bit from probability. It seems it achieves good results when the rates are |
This is great Anil. let's talk about seed init on Monday. |
rand ^= mask; | ||
} | ||
v_endif; | ||
TTI_SFPENCC(0,0,0,0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You shouldnt need to enable CC explicitly as by default CC is always enabled.
you just have to worry about reverting it to the correct state if CC is modified using your insstruction
Yes I did scale it but I assume its the responsibility of the op to make sure the input is that way. |
I actually had a bug in my test kernel , I tried to follow other kernels and initialized the PRNG before every tile. So effectively my results reflected the RNG for only one tile and got inaccurate results. After initializing only once before all the tiles I get very good results.
|
This looks great. The distribution should be even better for larger data sets |
004ad1d
to
7dd490c
Compare
7dd490c
to
6f9f9eb
Compare
Post commits passes with this branch https://github.com/tenstorrent/tt-metal/actions/runs/10200615586 |
How does the single seed get distributed to the 32 SFPUs? In my testing, I'm seeing all 32 vector lanes generate the same random number, which is not great, and implies I'm missing a step to cause the lanes to diverge. |
Are you trying to generate random numbers in a separate kernel ? Could you try initializing the seed and see if you get the same result ?
As for the dropout OP in python is implemented in such a way that the seed is reinitialized for every tile. Thus all the tiles will have similar pattern and this is going to be addressed in the future. |
My exact setup is somewhat bespoke, so I've tried to reproduce what I'm seeing using a minimally modified tt_metal programming example. Starting from // Init:
dropout_tile_init(0xDEADBEEF);
TTI_SFPMOV(0, p_sfpu::LTILEID, p_sfpu::LREG0, 0);
TTI_SFPSHFT(-1 & 0xfff, 0, p_sfpu::LREG0, 1);
// Per iteration:
TTI_SFPMOV(0, 9, p_sfpu::LREG0, 8);
TTI_SFPSTORE(0, 4, 3, 0);
TTI_SFPIADD(32, p_sfpu::LREG0, p_sfpu::LREG0, 5);
dst_reg++; Running with
Running with
On the surface, this looks plenty random, but problems appear as we dig in. The value in the top-left of the tile is
If we instead look at how the random values evolve as counter increases in steps of 32, we again see mostly a shift right by one each time:
Based on this, I'd guess that:
The result being that instead of 1024 independent random values, we've got 32 cursors into the same random sequence, with those cursors being so close together as to visit the same point in the sequence multiple times, meaning we end up with lots of correlation between the obtained values. |
Hello Peter, Sorry for the delay in answering and thank you very much for pointing out this issue. We have created an issue tenstorrent/tt-metal#13904 to to track this problem and will try to fix it. Thanks again. |
Implemented the dropout.
Used 31 bits from PRNG generator for perf.
Used 32 bit float for scale factor, in BUDA it is using 16 bits.
The seed initialization is very slow and requires 500 NOPS at least.
We could pull some code out of the dropout function and put in the initialization for performance but I tried to follow existing code.
Post commit tests pass (it was not being used by anything else) , I will run them again though when I make the pr to tt-metal.
https://github.com/tenstorrent/tt-metal/actions/runs/10087888953