mirror of
https://github.com/hpcaitech/ColossalAI.git
synced 2025-09-06 11:32:10 +00:00
[inference] Refactor inference architecture (#5057)
* [inference] support only TP (#4998) * support only tp * enable tp * add support for bloom (#5008) * [refactor] refactor gptq and smoothquant llama (#5012) * refactor gptq and smoothquant llama * fix import error * fix linear import torch-int * fix smoothquant llama import error * fix import accelerate error * fix bug * fix import smooth cuda * fix smoothcuda * [Inference Refactor] Merge chatglm2 with pp and tp (#5023) merge chatglm with pp and tp * [Refactor] remove useless inference code (#5022) * remove useless code * fix quant model * fix test import bug * mv original inference legacy * fix chatglm2 * [Refactor] refactor policy search and quant type controlling in inference (#5035) * [Refactor] refactor policy search and quant type controling in inference * [inference] update readme (#5051) * update readme * update readme * fix architecture * fix table * fix table * [inference] udpate example (#5053) * udpate example * fix run.sh * fix rebase bug * fix some errors * update readme * add some features * update interface * update readme * update benchmark * add requirements-infer --------- Co-authored-by: Bin Jia <45593998+FoolPlayer@users.noreply.github.com> Co-authored-by: Zhongkai Zhao <kanezz620@gmail.com>
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
"""
|
||||
Motivated by VllM (https://github.com/vllm-project/vllm), This module is trying to resolve the tokenizer issue.
|
||||
|
||||
license: MIT, see LICENSE for more details.
|
||||
"""
|
||||
|
||||
from transformers import AutoTokenizer
|
||||
|
||||
_FAST_LLAMA_TOKENIZER = "hf-internal-testing/llama-tokenizer"
|
||||
|
||||
|
||||
def get_tokenizer(
|
||||
tokenizer=None,
|
||||
tokenizer_name: str = "",
|
||||
trust_remote_code: bool = False,
|
||||
use_fast: bool = True,
|
||||
):
|
||||
if tokenizer is not None:
|
||||
tokenizer = tokenizer
|
||||
else:
|
||||
if "llama" in tokenizer_name.lower() and use_fast == True:
|
||||
print(
|
||||
"For some LLaMA-based models, initializing the fast tokenizer may "
|
||||
"take a long time. To eliminate the initialization time, consider "
|
||||
f"using '{_FAST_LLAMA_TOKENIZER}' instead of the original "
|
||||
"tokenizer. This is done automatically in Colossalai."
|
||||
)
|
||||
|
||||
tokenizer_name = _FAST_LLAMA_TOKENIZER
|
||||
|
||||
try:
|
||||
tokenizer = AutoTokenizer.from_pretrained(
|
||||
tokenizer_name, use_fast=use_fast, trust_remote_code=trust_remote_code
|
||||
)
|
||||
except TypeError:
|
||||
use_fast = False
|
||||
tokenizer = AutoTokenizer.from_pretrained(
|
||||
tokenizer_name, use_fast=use_fast, trust_remote_code=trust_remote_code
|
||||
)
|
||||
return tokenizer
|
Reference in New Issue
Block a user