Skip to content

Commit

Permalink
Fix torch integration test (#17923)
Browse files Browse the repository at this point in the history
Apart of #17490. Creating a torch tensor from a cudf.pandas proxy `Series` or `DataFrame` creates a device tensor if the underlying object is cudf. So this PR updates the `assert_eq` function in the module to convert the device tensor to a host tensor before comparing equality.

Authors:
  - Matthew Murray (https://github.com/Matt711)

Approvers:
  - Vyas Ramasubramani (https://github.com/vyasr)

URL: #17923
  • Loading branch information
Matt711 authored Feb 6, 2025
1 parent e2af6c9 commit 2da273c
Showing 1 changed file with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
# Copyright (c) 2023-2024, NVIDIA CORPORATION.
# Copyright (c) 2023-2025, NVIDIA CORPORATION.

import numpy as np
import pandas as pd
import pytest
import torch

pytestmark = pytest.mark.assert_eq(fn=torch.testing.assert_close)
pytestmark = pytest.mark.assert_eq(
fn=lambda expect, got, **kwargs: torch.testing.assert_close(
got, expect, **kwargs
)
)


def torch_ctor_assert_eq(expect, got, **kwargs):
assert got.is_cuda, "torch.Tensor should be on the device"
torch.testing.assert_close(got.to("cpu"), expect, **kwargs)


@pytest.fixture
Expand Down Expand Up @@ -116,9 +125,7 @@ def test_torch_train(data):
return model(test_x1, test_x2)


@pytest.mark.skip(
reason="AssertionError: The values for attribute 'device' do not match: cpu != cuda:0."
)
@pytest.mark.assert_eq(fn=torch_ctor_assert_eq)
def test_torch_tensor_ctor():
s = pd.Series(range(5))
return torch.tensor(s.values)
Expand Down

0 comments on commit 2da273c

Please sign in to comment.