Skip to content

Add test case for cache #20

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
59 changes: 57 additions & 2 deletions tests/models/test_decoders.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@
os.environ["VLLM_DT_MAX_CONTEXT_LEN"] = str((((max(common_seq_lengths) + max(common_max_new_tokens)) // 64) + 1) * 64)
os.environ["VLLM_DT_MAX_BATCH_SIZE"] = str(max(common_batch_sizes))

cache_params = list(itertools.product([common_model_paths[0]], [common_batch_sizes[0]], [common_seq_lengths[0]], [common_max_new_tokens[0]], ["miss", "hit"]))

# thresholds are chosen based on 1024 tokens per sequence
# 1% error threshold rate between cpu fp32 and cuda fp16
# if a models failure thresholds do not exist in this dict, default to the default_metrics_threshold defined above
Expand Down Expand Up @@ -214,7 +216,7 @@ def reset_compiler():
torch.compiler.reset()
torch._dynamo.reset()
os.environ.pop("COMPILATION_MODE", None)

os.environ.pop('TORCH_SENDNN_CACHE_ENABLE', None)

# TODO: Currently, gptq does not have the same level of support as non-gptq models for get_model. This method provides the extra requirements for gptq for get_model,
# however ideally, these fixes should be done in foundation-model-stack.
Expand Down Expand Up @@ -260,7 +262,6 @@ def __maybe_get_gptq_kwargs(model_path):
pass
return gptq_kwargs_aiu, gptq_kwargs_cpu


def __prepare_inputs(batch_size, seq_length, tokenizer, seed=0):
prompts_and_sizes = sample_sharegpt_requests(
SHARE_GPT_DATASET_PATH,
Expand Down Expand Up @@ -620,3 +621,57 @@ def _metric_calculator(r: torch.Tensor, t: torch.Tensor):
print("passed validation level 1")
else:
print("passed validation level 0")

@pytest.mark.parametrize("model_path,batch_size,seq_length,max_new_tokens,cache_status", cache_params)
def test_cache(model_path, batch_size, seq_length, max_new_tokens, cache_status):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need to parametrize everything here other than the miss and hit. Just specify them inside the test.

torch.manual_seed(42)
os.environ["TORCH_SENDNN_CACHE_ENABLE"] = "1"
os.environ["COMPILATION_MODE"] = "offline_decoder"

dprint(f"testing with cache: model={model_path}, batch_size={batch_size}, seq_length={seq_length}, max_new_tokens={max_new_tokens}, micro_model={USE_MICRO_MODELS}, cache={cache_status}")

if USE_MICRO_MODELS:
micro_model_kwargs = {"architecture": "hf_configured", "nlayers": 3}
else:
micro_model_kwargs = {"architecture": "hf_pretrained"}

if not USE_MICRO_MODELS and os.path.exists(model_path):
model_path_kwargs = {"model_path": model_path}
else:
model_path_kwargs = {"variant": model_path}

distributed_kwargs = {}
if USE_DISTRIBUTED:
distributed_kwargs["distr_param"] = "tp"
distributed_kwargs["group"] = dist.group.WORLD
get_model_kwargs = {**model_path_kwargs, **micro_model_kwargs, **distributed_kwargs}

tokenizer = tokenizers.get_tokenizer(model_path)

# prepare the AIU model
model = get_model(
device_type="cpu",
fused_weights=False,
**get_model_kwargs
)

model.eval()
torch.set_grad_enabled(False)
model.compile(backend="sendnn_decoder")


# prepare input_ids
input_ids, padding_kwargs = __prepare_inputs(batch_size, seq_length, tokenizer)

# warmup aiu model
warmup_model(model, input_ids, max_new_tokens, **padding_kwargs)

# aiu validatation
aiu_validation_info = extract_validation_information(
model,
input_ids,
max_new_tokens,
None,
only_last_token=True,
**padding_kwargs
)