Skip to content

Use zero-copy outputs with PyTorch #5699

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

Merged
merged 3 commits into from
Nov 6, 2024

Conversation

mzient
Copy link
Contributor

@mzient mzient commented Nov 5, 2024

Category:

Optimization

Description:

When using the dynamic executor, the outputs can be safely transferred (they won't be overwritten). This PR implements zero-copy outputs along with tests. It also updates the RN50 training script to use the new executor.

Additional information:

Affected modules and functionalities:

Key points relevant for the review:

Tests:

  • Existing tests apply
  • New tests added
    • Python tests
    • GTests
    • Benchmark
    • Other
  • N/A

Checklist

Documentation

  • Existing documentation applies
  • Documentation updated
    • Docstring
    • Doxygen
    • RST
    • Jupyter
    • Other
  • N/A

DALI team only

Requirements

  • Implements new requirements
  • Affects existing requirements
  • N/A

REQ IDs: N/A

JIRA TASK: N/A

@mzient mzient force-pushed the zero_copy_outputs_pytorch branch from 4c11075 to 9e1f0bb Compare November 5, 2024 14:43
@mzient mzient force-pushed the zero_copy_outputs_pytorch branch from 9e1f0bb to 4a94a74 Compare November 5, 2024 14:43
@dali-automaton
Copy link
Collaborator

CI MESSAGE: [20097716]: BUILD STARTED

@dali-automaton
Copy link
Collaborator

CI MESSAGE: [20097716]: BUILD PASSED

feed_ndarray(tensor, pyt_tensors[category], cuda_stream=stream)
else:
feed_ndarray(tensor, pyt_tensors[category])
if isinstance(tensor, TensorGPU):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in the previous code we were also matching TensorListGPU. Can you provide some background for this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was dead code. We replace TensorList with a tensor in line 254:

category_tensors[category] = out.as_tensor()

pyt_tensors[category] = [
torch.empty(
shape,
if copy:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OMG, GitHub made a big mess here. It's just indented and reformatted. Nothing more happened in the if copy branch.

@@ -1575,7 +1586,7 @@ def test_pytorch_iterator_pass_reader_name():
LastBatchPolicy.FILL,
LastBatchPolicy.DROP,
]:
for iters in [1, 2, 3, 2 * shards_num]:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Varying the number of iterations doesn't add anything to the test.

pyt_tensors[category] = [
torch.empty(
shape,
if copy:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method is long and complex. My advice is to refactor it into shorter methods.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be a complex task of its own, given the number of local variables that would need to be passe around.

@mzient mzient merged commit 1119827 into NVIDIA:main Nov 6, 2024
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants