[PR #768] test: add GPU-free unit tests for host-side utility modules #770

Open
opened 2026-10-27 21:06:11 +00:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/deepseek-ai/DeepEP/pull/768
Author: @Dashener2
Created: 9/29/2026
Status: 🔄 Open

Base: main ← Head: test/host-utils-gpu-free


📝 Commits (1)

  • 4bee4d5 test: add GPU-free unit tests for host-side utility modules

📊 Changes

4 files changed (+219 additions, -1 deletions)

View changed files

📝 deep_ep/utils/math.py (+7 -1)
➕ tests/utils/test_math.py (+101 -0)
➕ tests/utils/test_semantic.py (+66 -0)
➕ tests/utils/test_testing.py (+45 -0)

📄 Description

Problem

Importing deep_ep runs check_nccl_so() and init_jit(), which require the compiled
extension and a NCCL install, so the pure-Python helpers under deep_ep/utils/ could not
be tested on a machine without a GPU. While adding those tests, hash_tensor() turned out
to raise for common inputs.

Root cause

deep_ep/utils/math.py:

def hash_tensor(t: torch.Tensor) -> int:
    return t.view(torch.int).sum().item()

view(torch.int) requires a contiguous tensor with a 4-byte element size. It raises for
bool, int64, float16/bfloat16, and for non-contiguous tensors. hash_tensors is a
public helper under deep_ep.utils.math, so any caller hashing non-float32 test data hits
this.

Fix

Load the host modules directly by path so the tests do not import deep_ep, and make
hash_tensor dtype/layout agnostic:

def hash_tensor(t: torch.Tensor) -> int:
    t = t.contiguous()
    if t.element_size() == 4:
        return t.view(torch.int).sum().item()
    return t.view(torch.uint8).sum().item()

Testing

No GPU, no CUDA and no compiled extension required:

python tests/utils/test_math.py
python tests/utils/test_semantic.py
python tests/utils/test_testing.py

Verified with torch 2.8.0+cpu and numpy 1.26. The added hash test fails against the old
implementation with RuntimeError: self.stride(-1) must be 1 to view Long as Int.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/deepseek-ai/DeepEP/pull/768 **Author:** [@Dashener2](https://github.com/Dashener2) **Created:** 9/29/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `test/host-utils-gpu-free` --- ### 📝 Commits (1) - [`4bee4d5`](https://github.com/deepseek-ai/DeepEP/commit/4bee4d54ac9e2feada735382b9fd2ed6ac357a79) test: add GPU-free unit tests for host-side utility modules ### 📊 Changes **4 files changed** (+219 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `deep_ep/utils/math.py` (+7 -1) ➕ `tests/utils/test_math.py` (+101 -0) ➕ `tests/utils/test_semantic.py` (+66 -0) ➕ `tests/utils/test_testing.py` (+45 -0) </details> ### 📄 Description ## Problem Importing `deep_ep` runs `check_nccl_so()` and `init_jit()`, which require the compiled extension and a NCCL install, so the pure-Python helpers under `deep_ep/utils/` could not be tested on a machine without a GPU. While adding those tests, `hash_tensor()` turned out to raise for common inputs. ## Root cause `deep_ep/utils/math.py`: ```python def hash_tensor(t: torch.Tensor) -> int: return t.view(torch.int).sum().item() ``` `view(torch.int)` requires a contiguous tensor with a 4-byte element size. It raises for `bool`, `int64`, `float16`/`bfloat16`, and for non-contiguous tensors. `hash_tensors` is a public helper under `deep_ep.utils.math`, so any caller hashing non-float32 test data hits this. ## Fix Load the host modules directly by path so the tests do not import `deep_ep`, and make `hash_tensor` dtype/layout agnostic: ```python def hash_tensor(t: torch.Tensor) -> int: t = t.contiguous() if t.element_size() == 4: return t.view(torch.int).sum().item() return t.view(torch.uint8).sum().item() ``` ## Testing No GPU, no CUDA and no compiled extension required: ```bash python tests/utils/test_math.py python tests/utils/test_semantic.py python tests/utils/test_testing.py ``` Verified with `torch 2.8.0+cpu` and `numpy 1.26`. The added hash test fails against the old implementation with `RuntimeError: self.stride(-1) must be 1 to view Long as Int`. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
deepseek-ai/DeepEP#770
No description provided.