-
Notifications
You must be signed in to change notification settings - Fork 558
Add xla random generator. #9539
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
base: master
Are you sure you want to change the base?
Conversation
@qihqi please review |
a kindly ping @qihqi |
Just to understand: so the GeneratorImpl doesn't actually implement the RNG algorithm only manages the state? |
|
||
auto state_tensor = at::empty({(int64_t)total_size}, at::TensorOptions().dtype(at::kByte).device(at::kCPU)); | ||
uint8_t* data_ptr = state_tensor.data_ptr<uint8_t>(); | ||
memcpy(data_ptr, &state_->seed_, seed_size); |
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.
nit: can probably write to state_tensor.index(0).fill_( ...)
to write to the tensor.
that is correct. it is exactly what https://github.com/pytorch/pytorch/blob/main/aten/src/ATen/cuda/CUDAGeneratorImpl.h does. the idea is that the generator manages the state and different RNG algorithm generates the random numbers based on the state obtained from the generator. |
@qihqi is there anyway to auto-format the cpp code? i know we use |
nvm, i found the linter uses |
it seems that the failed tests are not related to this change. i've formatted the files. I don't have the permission to run the tests, please trigger them for me. also, merge if it LGTY. thanks! @qihqi |
This is the very first PR for #9159. It purely add the generator without any utilization of it. #9159 (comment) comment outlines the steps for entire change.