Skip to content

Commit

Permalink
update test scripts
Browse files Browse the repository at this point in the history
Signed-off-by: chensuyue <[email protected]>
  • Loading branch information
chensuyue committed Jul 10, 2024
1 parent 012081a commit 2697120
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 27 deletions.
4 changes: 2 additions & 2 deletions .azure-pipelines/template/docker-template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ steps:
script: |
docker ps -a
if [[ $(docker ps -a | grep -i '${{ parameters.containerName }}'$) ]]; then
docker start $(docker ps -aq)
docker start $(docker ps -aq --filter "name=${{ parameters.containerName }}")
echo "remove left files through container ..."
docker exec ${{ parameters.containerName }} bash -c "ls -a /neural-compressor && rm -fr /neural-compressor/* && rm -fr /neural-compressor/.* && ls -a /neural-compressor || true"
fi
Expand Down Expand Up @@ -78,7 +78,7 @@ steps:
displayName: "Pull habana docker image"
- script: |
docker stop $(docker ps -aq)
docker stop $(docker ps -aq --filter "name=${{ parameters.containerName }}")
docker rm -vf ${{ parameters.containerName }} || true
env | sort
displayName: "Clean docker container"
Expand Down
47 changes: 22 additions & 25 deletions test/3x/torch/algorithms/fp8_quant/test_basic.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,29 @@
import os
import sys
import torch
import time

import habana_frameworks.torch.core as htcore
import torch

from torch.utils.data import DataLoader
from torchvision import transforms, datasets
import torch.nn as nn
import torch.nn.functional as F
from torch.utils.data import DataLoader
from torchvision import datasets, transforms


class Net(nn.Module):
def __init__(self):
super(Net, self).__init__()
self.fc1 = nn.Linear(784, 256)
self.fc2 = nn.Linear(256, 64)
self.fc3 = nn.Linear(64, 10)

self.fc1 = nn.Linear(784, 256)
self.fc2 = nn.Linear(256, 64)
self.fc3 = nn.Linear(64, 10)
def forward(self, x):
out = x.view(-1, 28 * 28)
out = x.view(-1,28*28)
out = F.relu(self.fc1(out))
out = F.relu(self.fc2(out))
out = self.fc3(out)
out = F.log_softmax(out, dim=1)
return out


model = Net()
model_link = "https://vault.habana.ai/artifactory/misc/inference/mnist/mnist-epoch_20.pth"
model_path = "/tmp/.neural_compressor/mnist-epoch_20.pth"
Expand All @@ -38,25 +36,24 @@ def forward(self, x):
model = model.to("hpu")


model = torch.compile(model, backend="hpu_backend")

transform=transforms.Compose([
transforms.ToTensor(),
transforms.Normalize((0.1307,), (0.3081,))])

transform = transforms.Compose([transforms.ToTensor(), transforms.Normalize((0.1307,), (0.3081,))])

data_path = "./data"
test_dataset = datasets.MNIST(data_path, train=False, download=True, transform=transform)
test_loader = torch.utils.data.DataLoader(test_dataset, batch_size=32)
data_path = './data'
test_kwargs = {'batch_size': 32}
dataset1 = datasets.MNIST(data_path, train=False, download=True, transform=transform)
test_loader = torch.utils.data.DataLoader(dataset1,**test_kwargs)

correct = 0
with torch.no_grad():
for data, label in test_loader:
for batch_idx, (data, label) in enumerate(test_loader):

data = data.to("hpu")

data = data.to("hpu")
output = model(data)

label = label.to("hpu")
htcore.mark_step()

output = model(data)
correct += output.argmax(1).eq(label).sum().item()
correct += output.max(1)[1].eq(label).sum()

accuracy = correct / len(test_loader.dataset) * 100
print("Inference with torch.compile Completed. Accuracy: {:.2f}%".format(accuracy))
print('Accuracy: {:.2f}%'.format(100. * correct / (len(test_loader) * 32)))

0 comments on commit 2697120

Please sign in to comment.