Improve tokenizer loading fallback in bash/run.py
- Check whether the local tokenizer path actually exists before trying to load. - Log clear warnings when local path is missing or fails. - Respect USE_MODELSCOPE_HUB when falling back to remote model hub. - Raise a descriptive RuntimeError instead of silently retrying HuggingFace and hanging on network-unreachable errors.
This commit is contained in:
parent
a194724bcb
commit
5f0b63bf0f
43
bash/run.py
43
bash/run.py
@ -40,6 +40,9 @@ import yaml
|
|||||||
from evalscope import run_task, TaskConfig
|
from evalscope import run_task, TaskConfig
|
||||||
from evalscope.api.agent import NativeAgentConfig
|
from evalscope.api.agent import NativeAgentConfig
|
||||||
from evalscope.config import SandboxTaskConfig
|
from evalscope.config import SandboxTaskConfig
|
||||||
|
from evalscope.utils.logger import get_logger
|
||||||
|
|
||||||
|
logger = get_logger()
|
||||||
|
|
||||||
SCRIPT_DIR = Path(__file__).parent.resolve()
|
SCRIPT_DIR = Path(__file__).parent.resolve()
|
||||||
PROJECT_ROOT = SCRIPT_DIR.parent
|
PROJECT_ROOT = SCRIPT_DIR.parent
|
||||||
@ -281,13 +284,43 @@ _TOKENIZER = None
|
|||||||
|
|
||||||
def get_tokenizer(tokenizer_path: str):
|
def get_tokenizer(tokenizer_path: str):
|
||||||
global _TOKENIZER
|
global _TOKENIZER
|
||||||
if _TOKENIZER is None:
|
if _TOKENIZER is not None:
|
||||||
from transformers import AutoTokenizer
|
return _TOKENIZER
|
||||||
|
|
||||||
|
from transformers import AutoTokenizer
|
||||||
|
import os
|
||||||
|
|
||||||
|
# Try local path first
|
||||||
|
if tokenizer_path and os.path.exists(tokenizer_path):
|
||||||
try:
|
try:
|
||||||
_TOKENIZER = AutoTokenizer.from_pretrained(tokenizer_path, trust_remote_code=True)
|
_TOKENIZER = AutoTokenizer.from_pretrained(tokenizer_path, trust_remote_code=True)
|
||||||
except Exception:
|
logger.info(f'Loaded tokenizer from local path: {tokenizer_path}')
|
||||||
_TOKENIZER = AutoTokenizer.from_pretrained('deepseek-ai/DeepSeek-V4-Flash', trust_remote_code=True)
|
return _TOKENIZER
|
||||||
return _TOKENIZER
|
except Exception as e:
|
||||||
|
logger.warning(f'Failed to load tokenizer from local path {tokenizer_path}: {e}')
|
||||||
|
|
||||||
|
# If a local path was explicitly provided but does not exist, warn clearly
|
||||||
|
if tokenizer_path and tokenizer_path != '/data1/models/DeepSeek-V4-Flash-INT8':
|
||||||
|
logger.warning(f'Local tokenizer path does not exist: {tokenizer_path}. '
|
||||||
|
f'Will try to download from model hub.')
|
||||||
|
|
||||||
|
# Fallback: try model hub. Respect ModelScope hub if configured.
|
||||||
|
fallback_model = 'deepseek-ai/DeepSeek-V4-Flash'
|
||||||
|
hub_source = 'ModelScope' if os.environ.get('USE_MODELSCOPE_HUB') == '1' else 'HuggingFace'
|
||||||
|
logger.info(f'Trying to load tokenizer from {hub_source}: {fallback_model}')
|
||||||
|
try:
|
||||||
|
_TOKENIZER = AutoTokenizer.from_pretrained(fallback_model, trust_remote_code=True)
|
||||||
|
logger.info(f'Loaded tokenizer from {hub_source}: {fallback_model}')
|
||||||
|
return _TOKENIZER
|
||||||
|
except Exception as e:
|
||||||
|
raise RuntimeError(
|
||||||
|
f'Failed to load tokenizer.\n'
|
||||||
|
f' Local path: {tokenizer_path} (exists: {os.path.exists(tokenizer_path) if tokenizer_path else False})\n'
|
||||||
|
f' {hub_source} fallback: {fallback_model}\n'
|
||||||
|
f' Error: {e}\n'
|
||||||
|
f' Hint: mount the tokenizer to the container and set --tokenizer-path correctly, '
|
||||||
|
f'or set USE_MODELSCOPE_HUB=1 and HF_ENDPOINT=https://hf-mirror.com if downloading.'
|
||||||
|
) from e
|
||||||
|
|
||||||
|
|
||||||
def truncate_middle(text: str, max_tokens: int, tokenizer_path: str) -> str:
|
def truncate_middle(text: str, max_tokens: int, tokenizer_path: str) -> str:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user