Adding parallelization to "tfq.convert_to_tensor" for performance (#336) #793
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.
Overview
Hi, this is a draft pull request for improving the
tfq.convert_to_tensor
function by adding parallelization (#336). I'm confused about how the benchmarking suite works, so I am creating a draft pull request. For parallelization, I made sure to follow the Python documentation forconcurrent.futures
and usedProcessPoolExecutor
.Since the
convert_item
function is mostly CPU-bound and doesn't require heavy communication between processes, usingProcessPoolExecutor
should provide a significant speed-up for large inputs.I have simply added parallelization to the
tfq.convert_to_tensor
function and need help with benchmarking and testing.Changes
Parallelization: used
concurrent.futures.ProcessPoolExecutor
to parallelize the conversion of items. Each item in the list is processed independently, which allows for significant speedup for converting large lists of items.Docstrings: the original function had informative docstrings that described the
tfq.convert_to_tensor
function. I made sure to keep most of it and only added the necessary changes and fixed typos.Concerns
I wasn't able to benchmark my changes or run unit tests. I tried my best to follow the Contribution guidelines but ran into a lot of errors with Bazel. I am still working on the issue and wanted to inform you that the code has not been benchmarked using the Benchmark guidelines.
If the function needs to handle extremely deep nested lists, the
convert_item()
function may need to be iterative rather than recursive. However, the original author already made a comment to dismiss this concern.