-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Added specification for RandomUniform operation. #6196
Added specification for RandomUniform operation. #6196
Conversation
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.
Left one comment other looks good to me
Add plugin owners to the review |
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.
Please, add the rendered version of formulas to the PR description.
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.
Looks good. Let's pass the review from the technical writers and then merge the spec.
Co-authored-by: Tatiana Savina <[email protected]>
* Added RandomUniform specification. * Extended description of obtaining float numbers. * Added description of obtainin float16 and double values. * Added description of xor symbol. * Small correction. * Small corrections. * Added initial type attribute. * Corrected IR example, removed unnecessary default values. * Small correction. * Added information about type cast between initial and output types. * Removed initial type attribute. * Corrected output_type description. * Corrected minval, maxval description. Corrected IR example. * Apply suggestions from code review Co-authored-by: Tatiana Savina <[email protected]> * Removed unnecessary paper link. Co-authored-by: Tatiana Savina <[email protected]>
* Added RandomUniform specification. * Extended description of obtaining float numbers. * Added description of obtainin float16 and double values. * Added description of xor symbol. * Small correction. * Small corrections. * Added initial type attribute. * Corrected IR example, removed unnecessary default values. * Small correction. * Added information about type cast between initial and output types. * Removed initial type attribute. * Corrected output_type description. * Corrected minval, maxval description. Corrected IR example. * Apply suggestions from code review Co-authored-by: Tatiana Savina <[email protected]> * Removed unnecessary paper link. Co-authored-by: Tatiana Savina <[email protected]>
* Added RandomUniform specification. * Extended description of obtaining float numbers. * Added description of obtainin float16 and double values. * Added description of xor symbol. * Small correction. * Small corrections. * Added initial type attribute. * Corrected IR example, removed unnecessary default values. * Small correction. * Added information about type cast between initial and output types. * Removed initial type attribute. * Corrected output_type description. * Corrected minval, maxval description. Corrected IR example. * Apply suggestions from code review Co-authored-by: Tatiana Savina <[email protected]> * Removed unnecessary paper link. Co-authored-by: Tatiana Savina <[email protected]>
Details:
Tickets:
Algorithm description
RandomUniform operation generates random numbers from a uniform distribution in the range
[minval, maxval)
.The generation algorithm is based on underlying random integer generator that uses Philox algorithm. Philox algorithm
is counter based pseudo random generator, which produces uint32 values. Single invocation of Philox algorithm returns
four result random values, depending on the given key and counter values. Key and counter are initialized
with seed and seed2 attributes respectively.
key = seed
counter = seed2
Link to the original paper [Parallel Random Numbers: As Easy as 1, 2, 3]
(https://www.thesalmons.org/john/random123/papers/random123sc11.pdf)
The result of Philox is calculated by applying a fixed number of key and counter updating, so-called "rounds".
This implementation uses 4x32_10 version of Philox algorithm, where number of rounds = 10.
Suppose we have n which determines n-th 4 elements of random sequence.
In each round key, counter and n are splitted to pairs of uint32 values:
where cast_to_uint32 - static cast to uint32, value - uint64 input value, L, R - uint32
result values, >> - bitwise right shift.
Then n and counter are updated with the following formula:
where
- bitwise xor, k =
R_key
for updating counter, k =L_key
for updating n,M =
0xD2511F53
for updating n, M =0xCD9E8D57
for updating counter.After each round key is raised by summing with another pair of const values:
L += 0x9E3779B9
R += 0xBB67AE85
Values L'_n, R'_n, L'_counter, R'_counter are resulting four random numbers.
Float values between [0..1) are obtained from 32-bit integers by the following rules.
Float16 is formatted as follows: sign(1 bit) exponent(5 bits) mantissa(10 bits). The value is interpreted
using following formula:
so to obtain float16 values sign, exponent and mantissa are set as follows:
So the resulting float16 value is:
where x is uint32 generated random value.
Float32 is formatted as follows: sign(1 bit) exponent(8 bits) mantissa(23 bits). The value is interpreted
using following formula:
so to obtain float values sign, exponent and mantissa are set as follows:
So the resulting float value is:
where x is uint32 generated random value.
Double is formatted as follows: sign(1 bit) exponent(11 bits) mantissa(52 bits). The value is interpreted
using following formula:
so to obtain double values sign, exponent and mantissa are set as follows:
So the resulting double is obtained as follows:
where x0, x1 are uint32 generated random values.
To obtain a value in a specified range each value is processed with the following formulas:
For float values:

where x is random float or double value between [0..1).
For integer values:

where x is uint32 random value.