Skip to content

Commit

Permalink
[SW-193263] Switch HQT unit tests to run on INC
Browse files Browse the repository at this point in the history
Modify test to point to the correct package in INC instead of HQT.
Add __init__.py file to include needed content for test_layers' tests.

Change-Id: If47acdfc9f7521a54a7f350a444711a7c2b3e5b2
  • Loading branch information
Tiefen-boop committed Jul 29, 2024
1 parent a5b6ef8 commit 7bf9521
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 25 deletions.
8 changes: 4 additions & 4 deletions test/3x/torch/algorithms/fp8_quant/fp8_tests.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import habana_frameworks.torch.core as htcore
import habana_quantization_toolkit
import torch
import habana_frameworks.torch.core as htcore
import neural_compressor.torch.algorithms.fp8_quant

# This file is for small tests run for debug flow and accuracy. (Not for CI)

Expand Down Expand Up @@ -73,7 +73,7 @@ def forward(self, x, b):
model.eval()
model = model.to("hpu").to(torch.bfloat16)
htcore.hpu_initialize()
habana_quantization_toolkit.prep_model(model) # fp8 additions
neural_compressor.torch.algorithms.fp8_quant.prep_model(model) # fp8 additions


with torch.no_grad():
Expand Down Expand Up @@ -170,4 +170,4 @@ def forward(self, x, b):
# 5) tensor([[232.]], device='hpu:0', dtype=torch.bfloat16)

# fp8 additions
habana_quantization_toolkit.finish_measurements(model)
neural_compressor.torch.algorithms.fp8_quant.finish_measurements(model)
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import pytest
import torch
from habana_quantization_toolkit._quant_common.quant_config import ScaleMethod
from habana_quantization_toolkit.tests import TestVector, run_accuracy_test
from neural_compressor.torch.algorithms.fp8_quant._quant_common.quant_config import ScaleMethod
from ..tester import run_accuracy_test, TestVector


class LinearBlock(torch.nn.Module):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
"""Use this module as an example of how to write new unit tests for layers."""

import habana_quantization_toolkit as hqt
import os
import torch
from habana_quantization_toolkit._quant_common.helper_modules import Matmul
from habana_quantization_toolkit._quant_common.quant_config import QuantMode
import neural_compressor.torch.algorithms.fp8_quant as fp8_quant
from neural_compressor.torch.algorithms.fp8_quant._quant_common.quant_config import QuantMode
from neural_compressor.torch.algorithms.fp8_quant._quant_common.helper_modules import Matmul


class Model(torch.nn.Module):
Expand All @@ -20,6 +20,7 @@ def test_config_json():
QuantMode.MEASURE: "measure",
QuantMode.QUANTIZE: "quant",
}[mode]
config_path = f"llama_{name}"
hqt.prep_model(model, config_path=config_path)
hqt.finish_measurements(model)
config_path = os.path.join(os.environ.get("NEURAL_COMPRESSOR_FORK_ROOT"),
f"neural_compressor/torch/algorithms/fp8_quant/custom_config/llama_{name}.json")
fp8_quant.prep_model(model, config_path=config_path)
fp8_quant.finish_measurements(model)
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import itertools
from typing import Iterable, Tuple

import habana_frameworks.torch.utils.experimental as htexp
import pytest
import torch
from habana_quantization_toolkit._core.fp_utils import FP8_143_SCALES
from habana_quantization_toolkit._quant_common.helper_modules import matmul_fp8
from neural_compressor.torch.algorithms.fp8_quant._core.fp_utils import FP8_143_SCALES
from neural_compressor.torch.algorithms.fp8_quant._quant_common.helper_modules import matmul_fp8
import habana_frameworks.torch.utils.experimental as htexp


def run_test_matmul_fp8(
Expand Down
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import pytest
import torch
from habana_quantization_toolkit._quant_common.quant_config import ScaleMethod
from habana_quantization_toolkit.tests import TestVector, run_accuracy_test
from neural_compressor.torch.algorithms.fp8_quant._quant_common.quant_config import ScaleMethod
from ...tester import run_accuracy_test, TestVector


def get_test_vectors(*, dtype: torch.dtype, C_in: int, H: int, W: int) -> typing.Iterable[TestVector]:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import pytest
import torch
from habana_quantization_toolkit._quant_common.quant_config import ScaleMethod
from habana_quantization_toolkit.tests import TestVector, run_accuracy_test
from neural_compressor.torch.algorithms.fp8_quant._quant_common.quant_config import ScaleMethod
from ...tester import run_accuracy_test, TestVector


def get_test_vectors(*, dtype: torch.dtype, N: int, D_in: int) -> typing.Iterable[TestVector]:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import pytest
import torch
from habana_quantization_toolkit._quant_common.quant_config import ScaleMethod
from habana_quantization_toolkit.tests import TestVector, run_accuracy_test
from neural_compressor.torch.algorithms.fp8_quant._quant_common.quant_config import ScaleMethod
from ...tester import run_accuracy_test, TestVector


def get_test_vectors(*, dtype: torch.dtype) -> typing.Iterable[TestVector]:
Expand Down Expand Up @@ -31,8 +31,8 @@ def get_test_vectors(*, dtype: torch.dtype) -> typing.Iterable[TestVector]:


class Matmul(torch.nn.Module):
"""This is a mimic of other implementations of `Matmul`.
"""
This is a mimic of other implementations of `Matmul`.
It is here to not create a dependency on optimum-habana (which is logically needed).
It should not be used directly in user code.
"""
Expand Down

0 comments on commit 7bf9521

Please sign in to comment.