Skip to content
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

Handle empty tensors (must bind at minimum 4 bytes on wgpu) #86

Merged
merged 1 commit into from
Aug 28, 2024

Conversation

laggui
Copy link
Member

@laggui laggui commented Aug 28, 2024

Some operations could return empty tensors (e.g., argwhere for a tensor where all elements are zero).

Trying to return an empty tensor with 0 byte alloc would fail on wgpu, as encountered in Burn issues (2180, 1946).

We can handle empty tensors by allocating 4 bytes (minimum required by wgpu).

We get the same result as other backends:

Tensor {
  data:
[],
  shape:  [0, 1],
  device:  BestAvailable,
  backend:  "fusion<jit<wgpu>>",
  kind:  "Int",
  dtype:  "i32",
}

@nathanielsimard nathanielsimard merged commit aebf106 into main Aug 28, 2024
1 of 2 checks passed
@nathanielsimard nathanielsimard deleted the fix/wgpu/alloc-zero branch August 28, 2024 16:52
@ArthurBrussee
Copy link
Contributor

Wouldn't this also be an issue for kernels using client.empty()? Eg. if after no_true_vals.argwhere() I call .float().exp().

I thought the memory allocator handled allocating buffers of some minimum size behind the scenes.

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.

3 participants