Skip to content

Commit 6b3f3f7

Browse files
feat / fix: Properly make use of subfolder from HF models (#3072)
* add subfolder * lint * change it to empty string * fix typehints --------- Co-authored-by: Baber <[email protected]>
1 parent 0f63d4f commit 6b3f3f7

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

lm_eval/models/huggingface.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def __init__(
6161
backend: Literal["default", "causal", "seq2seq"] = "default",
6262
# override whether the model should be treated as decoder-only (causal) or encoder-decoder (seq2seq)
6363
revision: Optional[str] = "main",
64-
subfolder: Optional[str] = None,
64+
subfolder: str = "",
6565
tokenizer: Optional[
6666
Union[
6767
str,
@@ -162,14 +162,13 @@ def __init__(
162162
)
163163

164164
revision = str(revision) # cast to string if not already one
165-
# TODO: update this to be less of a hack once subfolder is fixed in HF
166-
revision = revision + ("/" + subfolder if subfolder is not None else "")
167165

168166
self._get_config(
169167
pretrained,
170168
revision=revision,
171169
trust_remote_code=trust_remote_code,
172170
gguf_file=gguf_file,
171+
subfolder=subfolder,
173172
)
174173

175174
# determine which of 'causal' and 'seq2seq' backends to use for HF models
@@ -182,6 +181,7 @@ def __init__(
182181
pretrained,
183182
tokenizer,
184183
revision=revision,
184+
subfolder=subfolder,
185185
trust_remote_code=trust_remote_code,
186186
use_fast_tokenizer=use_fast_tokenizer,
187187
gguf_file=gguf_file,
@@ -206,6 +206,7 @@ def __init__(
206206
gptqmodel=gptqmodel,
207207
gguf_file=gguf_file,
208208
quantization_config=getattr(self.config, "quantization_config", None),
209+
subfolder=subfolder,
209210
**kwargs,
210211
)
211212

@@ -522,13 +523,15 @@ def _get_config(
522523
revision: str = "main",
523524
trust_remote_code: bool = False,
524525
gguf_file: Optional[str] = None,
526+
subfolder: str = "",
525527
) -> None:
526528
"""Return the model config for HuggingFace models"""
527529
self._config = transformers.AutoConfig.from_pretrained(
528530
pretrained,
529531
revision=revision,
530532
trust_remote_code=trust_remote_code,
531533
gguf_file=gguf_file,
534+
subfolder=subfolder,
532535
)
533536

534537
def _create_model(
@@ -552,6 +555,7 @@ def _create_model(
552555
gptqmodel: Optional[bool] = False,
553556
gguf_file: Optional[str] = None,
554557
quantization_config: Optional[Dict[str, Any]] = None,
558+
subfolder: str = "",
555559
**kwargs,
556560
) -> None:
557561
"""
@@ -598,6 +602,7 @@ def _create_model(
598602
trust_remote_code=trust_remote_code,
599603
gguf_file=gguf_file,
600604
quantization_config=quantization_config,
605+
subfolder=subfolder,
601606
**model_kwargs,
602607
)
603608
else:
@@ -697,6 +702,7 @@ def _create_tokenizer(
697702
use_fast_tokenizer: Optional[bool] = True,
698703
gguf_file: Optional[str] = None,
699704
add_bos_token: Optional[bool] = False,
705+
subfolder: Optional[str] = "",
700706
) -> None:
701707
"""
702708
Helper method during initialization.
@@ -718,6 +724,9 @@ def _create_tokenizer(
718724
if add_bos_token:
719725
kwargs["add_bos_token"] = True
720726

727+
if subfolder:
728+
kwargs["subfolder"] = subfolder
729+
721730
if tokenizer:
722731
if isinstance(tokenizer, str):
723732
self.tokenizer = transformers.AutoTokenizer.from_pretrained(

0 commit comments

Comments
 (0)