@@ -246,18 +246,9 @@ def get_llm_output_logits(self, runner, op: LLMLogitScoresOp):
246246class HuggingFaceProvider (ModelProvider ):
247247 """Provider for HuggingFace Transformers models."""
248248
249- def _process_batches (self , log , inputs , op , output_hidden_states ):
250- import torch
249+ def _load_model (self , op : LLMLayerActivationsOp | LLMLogitScoresOp ):
251250 from transformers import AutoModelForCausalLM , AutoTokenizer
252- log = log .bind (device = op .device )
253-
254- if isinstance (op .text , (JSONColumnType , ConversationColumnType )) and not op .apply_chat_template :
255- raise ValueError ("HuggingFaceProvider requires apply_chat_template=True when using JSONColumnType for 'text'." )
256-
257- # Load model and tokenizer
258251 _ , model_name = get_model_provider (op .model_name )
259- log = log .bind (model_name = model_name )
260- log .info ("loading HuggingFace model" )
261252 tokenizer = AutoTokenizer .from_pretrained (model_name )
262253 model = AutoModelForCausalLM .from_pretrained (
263254 model_name ,
@@ -266,6 +257,19 @@ def _process_batches(self, log, inputs, op, output_hidden_states):
266257 )
267258 # note: there is a difference between from_pretrained(torch_dtype='float16') and model.half()
268259 model .eval ()
260+ return model
261+
262+ def _process_batches (self , log , inputs , op , output_hidden_states ):
263+ import torch
264+ log = log .bind (device = op .device )
265+
266+ if isinstance (op .text , (JSONColumnType , ConversationColumnType )) and not op .apply_chat_template :
267+ raise ValueError ("HuggingFaceProvider requires apply_chat_template=True when using JSONColumnType for 'text'." )
268+
269+ # Load model and tokenizer
270+ log = log .bind (model_name = op .model_name )
271+ log .info ("loading HuggingFace model" )
272+ model = self ._load_model (op )
269273
270274 if op .torch_compile :
271275 model .compile (backend = 'eager' )
0 commit comments