Skip to content

Commit 1a78804

Browse files
authored
Qualcomm AI Engine Direct - HF LLM lm_eval lazy import (pytorch#20413)
### Summary When importing HF LLM lowering flow from QNN, Optimum-ExecuTorch will run into lm_eval import error. To resolve this issue, we need to make lm_eval lazily imported, meaning we only import when we actually use the library. ### Test plan NA
1 parent 3c359d4 commit 1a78804

1 file changed

Lines changed: 11 additions & 10 deletions

File tree

‎examples/qualcomm/oss_scripts/llm_utils/qnn_decoder_model_manager.py‎

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -171,16 +171,6 @@ def pt2e_calibrate(
171171
calibration_data,
172172
tokenizer_path,
173173
):
174-
try:
175-
from executorch.examples.qualcomm.oss_scripts.llm_utils.eval_decoder_model_qnn import (
176-
GraphModuleCalibrationWrapper,
177-
)
178-
from lm_eval.evaluator import simple_evaluate
179-
except ImportError:
180-
raise ImportError(
181-
"Please install the llm eval dependency via examples/models/llama/install_requirements.sh"
182-
)
183-
184174
tokenizer = get_tokenizer(tokenizer_path)
185175
logging.info(
186176
f"Calibrating with tasks: {calibration_tasks}, limit: {calibration_limit}, calibration_data: {calibration_data}, tokenizer_path: {tokenizer_path}, seq_length: {self.config.max_seq_len}"
@@ -211,6 +201,17 @@ def calibrate_template(
211201
max_len=calibration_seq_length,
212202
)
213203
if calibration_tasks is not None and calibration_limit is not None:
204+
# Import lazily so only import lm_eval when user use it.
205+
try:
206+
from executorch.examples.qualcomm.oss_scripts.llm_utils.eval_decoder_model_qnn import (
207+
GraphModuleCalibrationWrapper,
208+
)
209+
from lm_eval.evaluator import simple_evaluate
210+
except ImportError:
211+
raise ImportError(
212+
"Please install the llm eval dependency via examples/models/llama/install_requirements.sh"
213+
)
214+
214215
eval_wrapper = GraphModuleCalibrationWrapper(
215216
model=self.graph_module,
216217
tokenizer=tokenizer,

0 commit comments

Comments
 (0)