Skip to content

Commit c935a3d

Browse files
authoredApr 8, 2024
Set use_cache in ipex model tests (huggingface#649)
1 parent 4ddf9d6 commit c935a3d

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed
 

‎optimum/intel/ipex/modeling_base.py

+4
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@ def ipex_jit_trace(model, task, use_cache):
8989

9090
model.config.return_dict = False
9191

92+
if "past_key_values" in sample_inputs and use_cache:
93+
# Make sure the model will output past_key_values in generation tasks
94+
model.config.use_cache = True
95+
9296
model = ipex.optimize(model.eval(), dtype=model.dtype, inplace=True)
9397
# Disable repack while jit tracing to reduce the memory
9498
ipex._C.disable_jit_linear_repack()

‎tests/ipex/test_modeling.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ def test_compare_to_transformers(self, model_arch):
253253
def test_pipeline(self, model_arch):
254254
model_id = MODEL_NAMES[model_arch]
255255
tokenizer = AutoTokenizer.from_pretrained(model_id)
256-
model = IPEXModelForCausalLM.from_pretrained(model_id, export=True, use_cache=False)
256+
model = IPEXModelForCausalLM.from_pretrained(model_id, export=True)
257257
model.config.encoder_no_repeat_ngram_size = 0
258258
model.to("cpu")
259259
pipe = pipeline("text-generation", model=model, tokenizer=tokenizer)

0 commit comments

Comments
 (0)