Made address book fold indices buffers #335
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
#330 momentarily made address book tensor indices stay on the CPU. This is because the previous
to(device)
override was not called when the circuit was a submodule of another PyTorch model.This was still ok because PyTorch supports indexing tensors on the GPU using tensors on the CPU. However, this comes at the cost of additional transfer overhead between CPU and GPU.
A quick profilation (using the optimized circuit in compilation-options.ipynb) shows this, where
aten::to
,aten::_to_copy
andaten::copy_
take ~31% of overall CPU time when calling the circuit forward method. See the screenshot below.This PR makes the address book fold indices buffers in the
AddressBook
torch module. As such, they are automatically moved to the GPU only once (i.e., when calling the parent moduleto(device)
method).The profilation with these changes shows no
aten::to
operation at all, which also reduces the meaasured CUDA time. See screenshot below.