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

Non contiguous gradient tensor not checked (causes segmentation fault) #8443

Closed
oliver-batchelor opened this issue Dec 22, 2023 · 0 comments · Fixed by #8450
Closed

Non contiguous gradient tensor not checked (causes segmentation fault) #8443

oliver-batchelor opened this issue Dec 22, 2023 · 0 comments · Fixed by #8450

Comments

@oliver-batchelor
Copy link
Contributor

Non-contiguous gradient vectors currently cause segmentation faults as shown by example below!

import taichi as ti
import torch

@ti.kernel
def double_kernel(x:ti.types.ndarray(dtype=ti.f32, ndim=1), 
           out:ti.types.ndarray(dtype=ti.f32, ndim=1)):
  for i in range(x.shape[0]):
    out[i] = 2*x[i]


if __name__ == '__main__':
    ti.init(log_level=ti.DEBUG, debug=True)

    device = torch.device('cpu')
    params = torch.rand(1000, dtype=torch.float32, device=device)
    out = torch.zeros_like(params)

    double_kernel(params, out)

    out.requires_grad_(True)
    grad = torch.tensor([1.], dtype=torch.float32)
    out.grad = grad.expand(1000) # make a non contiguous tensor

    double_kernel.grad(params, out)
@github-project-automation github-project-automation bot moved this to Untriaged in Taichi Lang Dec 22, 2023
@github-project-automation github-project-automation bot moved this from Untriaged to Done in Taichi Lang Dec 27, 2023
bobcao3 added a commit that referenced this issue Dec 27, 2023
Fixes: #8443

### Brief Summary

copilot:summary

### Walkthrough

copilot:walkthrough

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

1 participant