Skip to content

Demonstrate adding a cuda build + cuda custom op to torchao #130

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

Closed
wants to merge 1 commit into from

Conversation

zou3519
Copy link
Contributor

@zou3519 zou3519 commented Apr 10, 2024

We copy-paste a CUDA kernel from torchvision for nms to serve as the example.

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Apr 10, 2024
]
}
if debug_mode:
extra_compile_args["cxx"].append("-g")
Copy link
Member

Choose a reason for hiding this comment

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

will likely need to conda install cuda -c nvidia in CI since I don't think nvcc will be available

setup.py Outdated
this_dir = os.path.dirname(os.path.abspath(__file__))
extensions_dir = os.path.join(this_dir, "torchao", "csrc")
sources = [
os.path.join(extensions_dir, p)
Copy link
Member

Choose a reason for hiding this comment

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

more of a nit but should this be a recursive=True so we can have kernels grouped by folders under the cuda/ folder

@@ -0,0 +1,181 @@
#include <ATen/ATen.h>
Copy link
Member

Choose a reason for hiding this comment

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

ok i guess as a first useful kernel to merge, I'm gonna adapt this example to use paged attention

#include <torch/library.h>
#include <torch/types.h>

TORCH_LIBRARY_FRAGMENT(torchao, m) {
Copy link
Member

@msaroufim msaroufim Apr 10, 2024

Choose a reason for hiding this comment

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

did you write this or was it codegened?

EDIT: My question is actually maybe can we codegen this? same as load_inline does

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is not codegenned. We could codegen it, but in general codegen adds more complexity. What were you thinking for the API?

We copy-paste a CUDA kernel from torchvision for nms to serve as the
example.
@zou3519 zou3519 changed the title Demonstrate adding a cuda build to torchao Demonstrate adding a cuda build + cuda custom op to torchao Apr 10, 2024
@cpuhrsch
Copy link
Contributor

Thanks for sending this!

I guess this needs some version guards because it requires features from the nightlies? Or is the CI failure real for 2.2?

Processing /home/runner/work/ao/ao
  Installing build dependencies: started
  Installing build dependencies: finished with status 'done'
  Getting requirements to build wheel: started
  Getting requirements to build wheel: finished with status 'error'
  error: subprocess-exited-with-error
  
  × Getting requirements to build wheel did not run successfully.
  │ exit code: 1
  ╰─> [17 lines of output]
      Traceback (most recent call last):
        File "/opt/hostedtoolcache/Python/3.9.19/x64/lib/python3.9/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 353, in <module>
          main()
        File "/opt/hostedtoolcache/Python/3.9.19/x64/lib/python3.9/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 335, in main
          json_out['return_val'] = hook(**hook_input['kwargs'])
        File "/opt/hostedtoolcache/Python/3.9.19/x64/lib/python3.9/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 11[8](https://github.com/pytorch-labs/ao/actions/runs/8634345339/job/23669554393?pr=130#step:5:9), in get_requires_for_build_wheel
          return hook(config_settings)
        File "/tmp/pip-build-env-4v28lou4/overlay/lib/python3.[9](https://github.com/pytorch-labs/ao/actions/runs/8634345339/job/23669554393?pr=130#step:5:10)/site-packages/setuptools/build_meta.py", line 325, in get_requires_for_build_wheel
          return self._get_build_requires(config_settings, requirements=['wheel'])
        File "/tmp/pip-build-env-4v28lou4/overlay/lib/python3.9/site-packages/setuptools/build_meta.py", line 295, in _get_build_requires
          self.run_setup()
        File "/tmp/pip-build-env-4v28lou4/overlay/lib/python3.9/site-packages/setuptools/build_meta.py", line 487, in run_setup
          super().run_setup(setup_script=setup_script)
        File "/tmp/pip-build-env-4v28lou4/overlay/lib/python3.9/site-packages/setuptools/build_meta.py", line 3[11](https://github.com/pytorch-labs/ao/actions/runs/8634345339/job/23669554393?pr=130#step:5:12), in run_setup
          exec(code, locals())
        File "<string>", line 7, in <module>
      ModuleNotFoundError: No module named 'torch'
      [end of output]
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
error: subprocess-exited-with-error

× Getting requirements to build wheel did not run successfully.
│ exit code: 1
╰─> See above for output.

note: This error originates from a subprocess, and is likely not a problem with pip.

@msaroufim msaroufim mentioned this pull request Apr 15, 2024
13 tasks
@msaroufim
Copy link
Member

This was upstreamed as part of #135

@msaroufim msaroufim closed this May 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants