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

[ROCm] Fix some kernels failed unit tests #2498

Merged
merged 10 commits into from
Feb 5, 2024

Conversation

hongxiayang
Copy link
Collaborator

@hongxiayang hongxiayang commented Jan 18, 2024

This pull request is to fix some of the failed unit tests in ROCm platform, specifically,

  • adjusted tests in test_activation.py, test_attention.py , test_pos_encoding.py and test_cache.py in tests/kernels to fix the failed tests
  • refactored the code to get default atol and rtol values for use in torch.allclose

Tests:
To run the associated tests on ROCm platform, first we need to be inside the docker container with ROCm pytorch and vllm install, and then copy the tests directory to the vllm installed location, and then run the test using pytest.

Use the environment variable PYTORCH_TEST_WITH_ROCM=1 if inside the ROCm 5.7 docker image as shown in the below example:
This environment variable is already set inside the ROCm 6.0 docker image.

root@xxx:/opt/conda/envs/py_3.10/lib/python3.10/site-packages/vllm-0.2.7+rocm573-py3.10-linux-x86_64.egg/vllm/tests/kernels# PYTORCH_TEST_WITH_ROCM=1 pytest test_activation.py
====================================================================================== test session starts ======================================================================================
platform linux -- Python 3.10.13, pytest-7.4.2, pluggy-1.3.0
rootdir: /opt/conda/envs/py_3.10/lib/python3.10/site-packages/vllm-0.2.7+rocm573-py3.10-linux-x86_64.egg/vllm/tests/kernels
plugins: shard-0.1.2, xdoctest-1.1.0, xdist-3.3.1, flakefinder-1.1.0, rerunfailures-12.0, hypothesis-5.35.1, anyio-3.7.1
collected 216 items                                                                                                                                                                             
Running 216 items in this shard

test_activation.py ...................................................................................................................................................................... [ 76%]
..................................................                                                                                                                                        [100%]

======================================================================================= warnings summary ========================================================================================
../../../../torch/cuda/__init__.py:546
  /opt/conda/envs/py_3.10/lib/python3.10/site-packages/torch/cuda/__init__.py:546: UserWarning: Can't initialize NVML
    warnings.warn("Can't initialize NVML")

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
================================================================================ 216 passed, 1 warning in 1.82s =================================================================================

@hongxiayang hongxiayang marked this pull request as ready for review January 18, 2024 21:59
@hongxiayang
Copy link
Collaborator Author

cc @tjtanaa

@@ -26,6 +27,7 @@
@pytest.mark.parametrize("seed", SEEDS)
@pytest.mark.parametrize("device", DEVICES)
@torch.inference_mode()
@skipIfRocm
Copy link
Contributor

@tjtanaa tjtanaa Jan 19, 2024

Choose a reason for hiding this comment

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

Continuing the discussion from
#2409 (comment)

Thanks for pointing out which tests failed in this case. We could handle this in a different PR?

I think resolving it in another PR could be better, if we still analysing the issue.
Based on my understanding, I remember fp16 and half is supported as a native operator in ROCm whereas bfloat16 operations are mostly handled by casting it to float as intermediate type, as shown in /opt/rocm/include/hip/amd_detail/amd_hip_bf16.h
https://github.com/ROCm/clr/blob/rocm-6.0.x/hipamd/include/hip/amd_detail/amd_hip_bf16.h
https://github.com/ROCm/clr/blob/rocm-6.0.x/hipamd/include/hip/amd_detail/amd_hip_bfloat16.h
https://github.com/ROCm/clr/tree/rocm-5.7.x/hipamd/include/hip/amd_detail/amd_hip_bf16.h
https://github.com/ROCm/clr/tree/rocm-5.7.x/hipamd/include/hip/amd_detail/amd_hip_bfloat16.h

Do you perhaps by chance have any clue as to why natively supported float16 behaves this way?

Choose a reason for hiding this comment

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

AMD HW does not have native bfloat16 arithmetic except for the matrix multiply operations.

@hongxiayang hongxiayang changed the title [ROCm] Fix and skip failed unit tests [ROCm] Fix some kernels failed unit tests Jan 22, 2024
Copy link
Contributor

@tjtanaa tjtanaa left a comment

Choose a reason for hiding this comment

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

LGTM.

@simon-mo
Copy link
Collaborator

Hmmm it seems some of the tests are failing due to allclose.

https://buildkite.com/vllm/ci/builds/495#018d323c-6fa7-47ed-a078-04a2bc14f21c/51-7825

We are soft-failing kernel test due to GPU memory, but it shouldn't have any other error than CUDAOutOfMemory.

@hongxiayang
Copy link
Collaborator Author

Hmmm it seems some of the tests are failing due to allclose.

https://buildkite.com/vllm/ci/builds/495#018d323c-6fa7-47ed-a078-04a2bc14f21c/51-7825

We are soft-failing kernel test due to GPU memory, but it shouldn't have any other error than CUDAOutOfMemory.

Will check the failed ones. May be the message below of "All checks have passed" can be "improved"?

@simon-mo
Copy link
Collaborator

Yeah i'm trying to figure that out sorry.

@hongxiayang
Copy link
Collaborator Author

Yeah i'm trying to figure that out sorry.

@simon-mo Can this pull request be merged now? The longer it stays, more potential conflict will occur.

Copy link
Collaborator

@simon-mo simon-mo left a comment

Choose a reason for hiding this comment

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

LGTM. Will merge once the tests are only OOM not accuracy off.

@simon-mo simon-mo merged commit 56f738a into vllm-project:main Feb 5, 2024
17 checks passed
hongxiayang added a commit to hongxiayang/vllm that referenced this pull request Feb 13, 2024
alexm-neuralmagic pushed a commit to neuralmagic/nm-vllm that referenced this pull request Feb 13, 2024
jvmncs pushed a commit to jvmncs/vllm that referenced this pull request Feb 14, 2024
xjpang pushed a commit to xjpang/vllm that referenced this pull request Feb 20, 2024
xjpang pushed a commit to xjpang/vllm that referenced this pull request Feb 22, 2024
xjpang pushed a commit to xjpang/vllm that referenced this pull request Mar 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants