Skip to content

Conv workspace via framework allocation - #222

Draft
asglover wants to merge 5 commits into
mainfrom
conv-workspace-via-framework-allocation
Draft

asglover wants to merge 5 commits into
mainfrom
conv-workspace-via-framework-allocation

Conversation

@asglover

Copy link
Copy Markdown
Collaborator

This PR moves the responsibility of allocating the workspace to the frameworks (jax, torch) at each call site

@vbharadwaj-bk

Copy link
Copy Markdown
Member

PyTorch changes are fine - JAX changes, I don't really see it solving the stream problem and, since the allocation is still taking place at the Python level, doesn't seem to move the needle much, so going to request that is rolled back.

An aside: you've got two existing PRs with pending edits, I've got to review changes for other contributor, and everyone has to do rebases every time main advances; do me a favor and try to keep the count of active PRs small.

jit.set_max_smem(0, forward_config_ref.smem);
jit.set_max_smem(4, forward_config_ref.smem);
jit.set_max_smem(FORWARD, forward_config_ref.smem);
jit.set_max_smem(DOUBLE_BACKWARD_A, forward_config_ref.smem);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Cool, thanks for making this an enum

Comment thread CHANGELOG.md

### Unreleased
**Changed**:
- The deterministic convolution workspace is now allocated by the framework (PyTorch / JAX) each call

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Mm - it was always allocated by the framework (albeit at the Python level) - more accurate to state that it's allocated inside the extension at the C++ level.

ffi::AnyBuffer workspace,
ffi::AnyBuffer workspace_in,
ffi::AnyBuffer transpose_perm,
ffi::Result<ffi::AnyBuffer> workspace,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why this change to the JAX function signatures? I don't see a reason why the workspace needs to be returned.

return torch::zeros(sizes, ref.options());
}

Tensor tensor_empty_bytes(const Tensor &ref, int64_t nbytes) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Seems like this function is unused?


@functools.cache
def conv_workspace_shape(kernel: str) -> jax.ShapeDtypeStruct:
size = json.loads(kernel)["kernel_prop"]["workspace_size"]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

So, not too happy with this set of changes on the JAX side; json.loads is nontrivial. Yes, I know it will get optimized away with jax.jit, but no reason to excessively saddle the non-JIT version.

This is effectively allocating a new workspace for every call and not moving the allocation into the C++ layer (which was the ostensible target of your PyTorch changes, so I don't really see this change moving the needle. Please roll back the JAX workspace changes.

Comment thread tests/cuda_graph_test.py
@@ -0,0 +1,123 @@
import pytest

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can you disable this test when pytest --jax is enabled?

Comment thread tests/cuda_graph_test.py
def step():
return _fwd_bwd(compiled, X, Y, W, rows, cols, sender_perm, G)

for _ in range(4):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why four times? And perhaps this test should live in compile_tests, not here?

Comment thread tests/cuda_graph_test.py
_assert_close(outputs, reference, deterministic)


def test_concurrent_streams_share_no_state(conv_and_inputs):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Would move to stream_tests.py

Comment thread tests/cuda_graph_test.py

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The tests in this file could probably live in the existing test files - only one deals with cuda graphs, and that could probably go in the compile_tests.py file.

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.

2 participants