Skip to content

Commit

Permalink
Fixed lint/format error
Browse files Browse the repository at this point in the history
Signed-off-by: Abukhoyer Shaik <[email protected]>
  • Loading branch information
abukhoy committed Oct 10, 2024
1 parent 478c2f0 commit 1d2d1fa
Show file tree
Hide file tree
Showing 6 changed files with 250 additions and 161 deletions.
148 changes: 93 additions & 55 deletions tests/compiler/test_compiler_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,17 @@

import pytest

import QEfficient
from QEfficient.cloud.export import get_onnx_model_path
from QEfficient.compile.compile_helper import compile
from QEfficient.utils import check_and_assign_cache_dir, get_qpc_dir_path


@pytest.mark.parametrize("model_name",["lu-vae/llama-68m-fft"])
class TestQEffCompileFunctions():
@pytest.mark.parametrize("model_name", ["lu-vae/llama-68m-fft"])
class TestQEffCompileFunctions:
@classmethod
def setup_method(cls):
cls.num_cores: int = 16
cls.device_group = [0] # FIXME: use num_devices instead
cls.device_group = [0] # FIXME: use num_devices instead
cls.aic_enable_depth_first: bool = False
cls.mos: int = -1
cls.batch_size: int = 1
Expand All @@ -38,12 +37,12 @@ def setup_method(cls):
for model_name in ["lu-vae/llama-68m-fft"]:
cache_dir = check_and_assign_cache_dir(cls.local_model_dir, cls.cache_dir)
onnx_model_path = get_onnx_model_path(
model_name=model_name,
cache_dir=cache_dir,
hf_token=cls.hf_token,
local_model_dir=cls.local_model_dir,
full_batch_size=cls.full_batch_size,
)
model_name=model_name,
cache_dir=cache_dir,
hf_token=cls.hf_token,
local_model_dir=cls.local_model_dir,
full_batch_size=cls.full_batch_size,
)
cls.models[model_name] = [str(onnx_model_path)]

def teardown_class(cls):
Expand All @@ -52,58 +51,97 @@ def teardown_class(cls):
if os.path.exists(os.path.dirname(dir)):
shutil.rmtree(os.path.dirname(dir))

def test_compile_for_mxint8(self,model_name):
def test_compile_for_mxint8(self, model_name):
self.mxint8 = True
qpc_dir_path = get_qpc_dir_path(model_name,self.num_cores,self.mos,self.batch_size,self.prompt_len,self.ctx_len,self.mxfp6,self.mxint8,self.device_group,self.full_batch_size)
result = compile(onnx_path = self.models[model_name][0],
qpc_path = os.path.dirname(qpc_dir_path),
num_cores = self.num_cores,
device_group = self.device_group, # FIXME: use num_devices instead
aic_enable_depth_first = self.aic_enable_depth_first,
mos = self.mos,
batch_size = self.batch_size,
prompt_len = self.prompt_len,
ctx_len = self.ctx_len,
mxfp6 = self.mxfp6,
mxint8 = self.mxint8,
custom_io_file_path = self.custom_io_file_path,
full_batch_size = self.full_batch_size)
qpc_dir_path = get_qpc_dir_path(
model_name,
self.num_cores,
self.mos,
self.batch_size,
self.prompt_len,
self.ctx_len,
self.mxfp6,
self.mxint8,
self.device_group,
self.full_batch_size,
)
result = compile(
onnx_path=self.models[model_name][0],
qpc_path=os.path.dirname(qpc_dir_path),
num_cores=self.num_cores,
device_group=self.device_group, # FIXME: use num_devices instead
aic_enable_depth_first=self.aic_enable_depth_first,
mos=self.mos,
batch_size=self.batch_size,
prompt_len=self.prompt_len,
ctx_len=self.ctx_len,
mxfp6=self.mxfp6,
mxint8=self.mxint8,
custom_io_file_path=self.custom_io_file_path,
full_batch_size=self.full_batch_size,
)
assert result == qpc_dir_path
self.models[model_name].append(qpc_dir_path)

def test_compile_for_fp16(self,model_name):
def test_compile_for_fp16(self, model_name):
self.mxint8 = False
qpc_dir_path = get_qpc_dir_path(model_name,self.num_cores,self.mos,self.batch_size,self.prompt_len,self.ctx_len,self.mxfp6,self.mxint8,self.device_group,self.full_batch_size)
result = compile(onnx_path = self.models[model_name][0],
qpc_path = os.path.dirname(qpc_dir_path),
num_cores = self.num_cores,
device_group = self.device_group, # FIXME: use num_devices instead
aic_enable_depth_first = self.aic_enable_depth_first,
mos = self.mos,
batch_size = self.batch_size,
prompt_len = self.prompt_len,
ctx_len = self.ctx_len,
mxfp6 = self.mxfp6,
mxint8 = self.mxint8,
custom_io_file_path = self.custom_io_file_path,
full_batch_size = self.full_batch_size)
qpc_dir_path = get_qpc_dir_path(
model_name,
self.num_cores,
self.mos,
self.batch_size,
self.prompt_len,
self.ctx_len,
self.mxfp6,
self.mxint8,
self.device_group,
self.full_batch_size,
)
result = compile(
onnx_path=self.models[model_name][0],
qpc_path=os.path.dirname(qpc_dir_path),
num_cores=self.num_cores,
device_group=self.device_group, # FIXME: use num_devices instead
aic_enable_depth_first=self.aic_enable_depth_first,
mos=self.mos,
batch_size=self.batch_size,
prompt_len=self.prompt_len,
ctx_len=self.ctx_len,
mxfp6=self.mxfp6,
mxint8=self.mxint8,
custom_io_file_path=self.custom_io_file_path,
full_batch_size=self.full_batch_size,
)
assert result == qpc_dir_path
self.models[model_name].append(qpc_dir_path)

def test_compile_for_IO_notFound(self,model_name):
qpc_dir_path = get_qpc_dir_path(model_name,self.num_cores,self.mos,self.batch_size,self.prompt_len,self.ctx_len,self.mxfp6,self.mxint8,self.device_group,self.full_batch_size)
def test_compile_for_IO_notFound(self, model_name):
qpc_dir_path = get_qpc_dir_path(
model_name,
self.num_cores,
self.mos,
self.batch_size,
self.prompt_len,
self.ctx_len,
self.mxfp6,
self.mxint8,
self.device_group,
self.full_batch_size,
)
with pytest.raises(FileNotFoundError):
compile(onnx_path = "",
qpc_path = os.path.dirname(qpc_dir_path),
num_cores = self.num_cores,
device_group = self.device_group, # FIXME: use num_devices instead
aic_enable_depth_first = self.aic_enable_depth_first,
mos = self.mos,
batch_size = self.batch_size,
prompt_len = self.prompt_len,
ctx_len = self.ctx_len,
mxfp6 = self.mxfp6,
mxint8 = self.mxint8,
custom_io_file_path = self.custom_io_file_path,
full_batch_size = self.full_batch_size)
compile(
onnx_path="",
qpc_path=os.path.dirname(qpc_dir_path),
num_cores=self.num_cores,
device_group=self.device_group, # FIXME: use num_devices instead
aic_enable_depth_first=self.aic_enable_depth_first,
mos=self.mos,
batch_size=self.batch_size,
prompt_len=self.prompt_len,
ctx_len=self.ctx_len,
mxfp6=self.mxfp6,
mxint8=self.mxint8,
custom_io_file_path=self.custom_io_file_path,
full_batch_size=self.full_batch_size,
)
self.models[model_name].append(qpc_dir_path)
56 changes: 30 additions & 26 deletions tests/exporter/test_export_hf_to_cloud_ai_100.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,19 @@
import QEfficient
from QEfficient.base.common import QEFFCommonLoader
from QEfficient.exporter.export_hf_to_cloud_ai_100 import (
convert_to_cloud_bertstyle,
convert_to_cloud_kvstyle,
qualcomm_efficient_converter,
)
from QEfficient.utils import load_hf_tokenizer, onnx_exists


def create_onnx_dir(model_name):
_,onnx_dir_path,_ = onnx_exists(model_name=model_name,full_batch_size=None)
_, onnx_dir_path, _ = onnx_exists(model_name=model_name, full_batch_size=None)
return onnx_dir_path

@pytest.mark.parametrize("model_name",["lu-vae/llama-68m-fft"])
class TestQEffExportFunctions():

@pytest.mark.parametrize("model_name", ["lu-vae/llama-68m-fft"])
class TestQEffExportFunctions:
@classmethod
def setup_class(cls):
cls.seq_len = 128
Expand All @@ -34,53 +34,57 @@ def setup_class(cls):
cls.models = {}
for model_name in ["lu-vae/llama-68m-fft"]:
onnx_dir_path = create_onnx_dir(model_name)
tokenizer = load_hf_tokenizer(pretrained_model_name_or_path=model_name,hf_token=cls.hf_token,cache_dir=cls.cache_dir)
model_kv = QEFFCommonLoader.from_pretrained(pretrained_model_name_or_path=model_name,token=cls.hf_token,cache_dir=cls.cache_dir)
tokenizer = load_hf_tokenizer(
pretrained_model_name_or_path=model_name, hf_token=cls.hf_token, cache_dir=cls.cache_dir
)
model_kv = QEFFCommonLoader.from_pretrained(
pretrained_model_name_or_path=model_name, token=cls.hf_token, cache_dir=cls.cache_dir
)
qeff_model = QEfficient.transform(model_kv)
cls.models[model_name] = [onnx_dir_path,tokenizer,model_kv,qeff_model]
cls.models[model_name] = [onnx_dir_path, tokenizer, model_kv, qeff_model]

def teardown_class(cls):
for models in cls.models.values():
onnx_dir_path = models[0]
if os.path.exists(onnx_dir_path):
shutil.rmtree(onnx_dir_path)
def test_convert_to_cloud_bertstyle(self,model_name):
_=model_name

def test_convert_to_cloud_bertstyle(self, model_name):
_ = model_name
assert True

def test_convert_to_cloud_kvstyle_success(self,model_name):
def test_convert_to_cloud_kvstyle_success(self, model_name):
"""
Test method for convert_to_cloud_kvstyle function in the case of general code flow that qeff_model is transformed
"""
onnx_dir_path,tokenizer,_,qeff_model = self.models[model_name]
onnx_dir_path, tokenizer, _, qeff_model = self.models[model_name]
result = convert_to_cloud_kvstyle(
model_name=model_name,
qeff_model=qeff_model,
tokenizer=tokenizer,
onnx_dir_path=onnx_dir_path,
seq_len=self.seq_len
seq_len=self.seq_len,
)
assert os.path.isfile(result)
assert os.path.exists(result)
def test_convert_to_cloud_kvstyle_warning(self,model_name):

def test_convert_to_cloud_kvstyle_warning(self, model_name):
"""
Test method for convert_to_cloud_kvstyle function in the case of Depcreation Warning in the function
"""
onnx_dir_path,tokenizer,_,qeff_model = self.models[model_name]
onnx_dir_path, tokenizer, _, qeff_model = self.models[model_name]
with pytest.warns(DeprecationWarning):
convert_to_cloud_kvstyle(
model_name=model_name,
qeff_model=qeff_model,
tokenizer=tokenizer,
onnx_dir_path=onnx_dir_path,
seq_len=self.seq_len
seq_len=self.seq_len,
)
def test_qualcomm_efficient_converter_success(self,model_name):

def test_qualcomm_efficient_converter_success(self, model_name):
"""
Test method for qualcomm_efficient_converter function in the case of general code flow
Test method for qualcomm_efficient_converter function in the case of general code flow
"""
result = qualcomm_efficient_converter(
model_name=model_name,
Expand All @@ -89,24 +93,24 @@ def test_qualcomm_efficient_converter_success(self,model_name):
onnx_dir_path=None,
seq_length=self.seq_len,
kv=True,
form_factor="cloud"
form_factor="cloud",
)
assert os.path.exists(result[0])
assert os.path.exists(result[1])

def test_qualcomm_efficient_converter_transformed_model(self,model_name):
def test_qualcomm_efficient_converter_transformed_model(self, model_name):
"""
Test method for qualcomm_efficient_converter function in the case of qeff_model is already transformed
Test method for qualcomm_efficient_converter function in the case of qeff_model is already transformed
"""
onnx_dir_path,tokenizer,_,qeff_model = self.models[model_name]
onnx_dir_path, tokenizer, _, qeff_model = self.models[model_name]
result = qualcomm_efficient_converter(
model_name=model_name,
model_kv=qeff_model,
tokenizer=tokenizer,
onnx_dir_path=onnx_dir_path,
seq_length=self.seq_len,
kv=True,
form_factor="cloud"
form_factor="cloud",
)
assert os.path.exists(result[0])
assert os.path.exists(result[1])
Loading

0 comments on commit 1d2d1fa

Please sign in to comment.