Skip to content

Commit b2ce359

Browse files
Merge pull request #10 from megagonlabs/spacy_v3.4
migrate to spacy v3.4
2 parents 727739d + ac9921c commit b2ce359

File tree

3 files changed

+12
-10
lines changed

3 files changed

+12
-10
lines changed

ginza_transformers/layers/hf_shim_custom.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,14 @@ def from_bytes(self, bytes_data):
124124
transformer.load_state_dict(torch.load(filelike, map_location=map_location))
125125
else:
126126
try:
127-
transformer = AutoModel.from_pretrained(config._name_or_path, local_files_only=True)
128-
except OSError as e2:
129-
print("trying to download model from huggingface hub:", config._name_or_path, "...", file=sys.stderr)
130-
transformer = AutoModel.from_pretrained(config._name_or_path)
131-
print("succeded", file=sys.stderr)
127+
transformer = AutoModel.from_pretrained(config_dict["_name_or_path"], local_files_only=True)
128+
except OSError as e1:
129+
try:
130+
transformer = AutoModel.from_pretrained(config._name_or_path)
131+
except OSError as e2:
132+
print("trying to download model from huggingface hub:", config_dict["_name_or_path"], "...", file=sys.stderr)
133+
transformer = AutoModel.from_pretrained(config_dict["_name_or_path"])
134+
print("succeded", file=sys.stderr)
132135

133136
transformer.to(map_location)
134137
self._model = transformer

ginza_transformers/layers/transformer_model.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,10 @@ def huggingface_from_pretrained_custom(
5555
try:
5656
trf_config["return_dict"] = True
5757
config = AutoConfig.from_pretrained(str_path, **trf_config)
58-
transformer = AutoModel.from_pretrained(str_path, config=config)
59-
except OSError as e:
58+
transformer = AutoModel.from_pretrained(model_name, local_files_only=True)
59+
except OSError as e1:
6060
try:
61-
transformer = AutoModel.from_pretrained(str_path, local_files_only=True)
61+
transformer = AutoModel.from_pretrained(str_path, config=config)
6262
except OSError as e2:
6363
model_name = str(source)
6464
print("trying to download model from huggingface hub:", model_name, "...", file=sys.stderr)

setup.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,10 @@
1212
},
1313
install_requires=[
1414
"spacy-transformers>=1.1.2,<1.2.0",
15-
"transformers<4.13.0",
1615
],
1716
license="MIT",
1817
name="ginza-transformers",
1918
packages=find_packages(include=["ginza_transformers", "ginza_transformers.layers"]),
2019
url="https://github.com/megagonlabs/ginza-transformers",
21-
version='0.4.1',
20+
version='0.4.2',
2221
)

0 commit comments

Comments
 (0)