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

added prototype GPU tests for T5 #2055

Merged
merged 1 commit into from
Feb 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test-linux-gpu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,4 @@ jobs:
# Run Tests
python3 -m torch.utils.collect_env
cd test
python3 -m pytest --junitxml=test-results/junit.xml -v --durations 20 torchtext_unittest/models/gpu_tests
python3 -m pytest --junitxml=test-results/junit.xml -v --durations 20 -m gpu_test torchtext_unittest
2 changes: 2 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
[pytest]
testpaths = test/
python_paths = ./
markers =
gpu_test: marks cuda tests
2 changes: 2 additions & 0 deletions test/torchtext_unittest/models/gpu_tests/models_gpu_test.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import unittest

import pytest
import torch
from torchtext_unittest.common.torchtext_test_case import TorchtextTestCase
from torchtext_unittest.models.models_test_impl import BaseTestModels


@pytest.mark.gpu_test
@unittest.skipIf(not torch.cuda.is_available(), reason="CUDA is not available")
class TestModels32GPU(BaseTestModels, TorchtextTestCase):
dtype = torch.float32
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import unittest

import pytest
import torch
from torchtext_unittest.common.torchtext_test_case import TorchtextTestCase
from torchtext_unittest.prototype.models.models_test_impl import BaseTestModels


@pytest.mark.gpu_test
@unittest.skipIf(not torch.cuda.is_available(), reason="CUDA is not available")
class TestModels32GPU(BaseTestModels, TorchtextTestCase):
dtype = torch.float32
device = torch.device("cuda")
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@

import torch
from torch.nn import functional as F
from torchtext_unittest.common.torchtext_test_case import TorchtextTestCase
from torchtext_unittest.common.case_utils import TestBaseMixin


class TestModels(TorchtextTestCase):
class BaseTestModels(TestBaseMixin):
def test_t5_bundler_build_model(self) -> None:
from torchtext.prototype.models import T5Conf, T5Model, T5Bundle

Expand Down Expand Up @@ -152,8 +152,8 @@ def test_t5_bundler_train(self) -> None:

def _train(model):
optim = SGD(model.parameters(), lr=1)
model_input = torch.tensor([[1, 2, 3, 4, 5]])
target = torch.tensor([1])
model_input = torch.tensor([[1, 2, 3, 4, 5]]).to(device=self.device)
target = torch.tensor([1]).to(device=self.device)
output = model(model_input)["decoder_output"]
logits = F.log_softmax(output[:, -1], dim=-1)
loss = F.cross_entropy(logits, target)
Expand All @@ -177,6 +177,7 @@ def _train(model):
freeze_model=False,
checkpoint=dummy_model.state_dict(),
)
model.to(device=self.device, dtype=self.dtype)
current_state_dict = copy.deepcopy(model.state_dict())

_train(model)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import torch
from torchtext_unittest.common.torchtext_test_case import TorchtextTestCase

from .models_test_impl import BaseTestModels


class TestModels32CPU(BaseTestModels, TorchtextTestCase):
dtype = torch.float32
device = torch.device("cpu")