Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support model revision and tokenizer revision in huggingface server #3558

Merged
merged 4 commits into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
format code
Signed-off-by: Lize Cai <lize.cai@sap.com>
  • Loading branch information
lizzzcai committed Apr 3, 2024
commit c9dbd049046534297d96d269d9b088f0b5138ea6
5 changes: 4 additions & 1 deletion python/huggingfaceserver/huggingfaceserver/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ def list_of_strings(arg):
"--model_revision", required=False, default=None, help="Huggingface model revision"
)
parser.add_argument(
"--tokenizer_revision", required=False, default=None, help="Huggingface tokenizer revision"
"--tokenizer_revision",
required=False,
default=None,
help="Huggingface tokenizer revision",
)
parser.add_argument(
"--max_length", type=int, default=None, help="max sequence length for the tokenizer"
Expand Down
8 changes: 5 additions & 3 deletions python/huggingfaceserver/huggingfaceserver/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def load(self) -> bool:

model_config = AutoConfig.from_pretrained(model_id_or_path, revision=revision)

if self.use_vllm and self.device == torch.device("cuda"): # vllm needs gpu
if self.use_vllm and self.device == torch.device("cuda"): # vllm needs gpu
if self.infer_vllm_supported_from_model_architecture(model_config):
logger.info("supported model by vLLM")
self.vllm_engine_args.tensor_parallel_size = torch.cuda.device_count()
Expand Down Expand Up @@ -162,13 +162,15 @@ def load(self) -> bool:
revision=tokenizer_revision,
do_lower_case=self.do_lower_case,
device_map=self.device_map,
padding_side="left")
padding_side="left",
)
else:
self.tokenizer = AutoTokenizer.from_pretrained(
model_id_or_path,
revision=tokenizer_revision,
do_lower_case=self.do_lower_case,
device_map=self.device_map)
device_map=self.device_map,
)

if not self.tokenizer.pad_token:
self.tokenizer.add_special_tokens({"pad_token": "[PAD]"})
Expand Down
28 changes: 20 additions & 8 deletions python/huggingfaceserver/huggingfaceserver/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,28 @@ def test_bert():
def test_model_revision():
# https://huggingface.co/google-bert/bert-base-uncased
commit = "86b5e0934494bd15c9632b12f734a8a67f723594"
model = HuggingfaceModel("bert-base-uncased",
{"model_id": "bert-base-uncased",
"model_revision": commit,
"tokenizer_revision": commit,
"disable_lower_case": False}
)
model = HuggingfaceModel(
"bert-base-uncased",
{
"model_id": "bert-base-uncased",
"model_revision": commit,
"tokenizer_revision": commit,
"disable_lower_case": False,
},
)
model.load()

response = asyncio.run(model({"instances": ["The capital of France is [MASK].",
"The capital of [MASK] is paris."]}, headers={}))
response = asyncio.run(
model(
{
"instances": [
"The capital of France is [MASK].",
"The capital of [MASK] is paris.",
]
},
headers={},
)
)
assert response == {"predictions": ["paris", "france"]}


Expand Down
Loading