mirror of
https://github.com/modelscope/modelscope.git
synced 2026-02-24 12:10:09 +01:00
ok Merge branch 'master' of github.com:modelscope/modelscope into release/1.19
This commit is contained in:
@@ -17,7 +17,8 @@ class DatasetContextConfig:
|
||||
data_files: Union[str, Sequence[str],
|
||||
Mapping[str, Union[str, Sequence[str]]]],
|
||||
download_mode: DownloadMode, cache_root_dir: str,
|
||||
use_streaming: bool, stream_batch_size: int, trust_remote_code: bool, **kwargs):
|
||||
use_streaming: bool, stream_batch_size: int,
|
||||
trust_remote_code: bool, **kwargs):
|
||||
|
||||
self._download_config = None
|
||||
self._data_meta_config = None
|
||||
|
||||
@@ -7,7 +7,7 @@ from typing import Any, Callable, Dict, Generator, Iterator, List, Tuple, Union
|
||||
import json
|
||||
import numpy as np
|
||||
import torch
|
||||
from transformers import PreTrainedModel, PreTrainedTokenizer
|
||||
from transformers import AutoConfig, PreTrainedModel, PreTrainedTokenizer
|
||||
|
||||
from modelscope import (AutoModelForCausalLM, AutoTokenizer, Pipeline,
|
||||
snapshot_download)
|
||||
@@ -170,9 +170,17 @@ class LLMPipeline(Pipeline, PipelineStreamingOutputMixin):
|
||||
**kwargs):
|
||||
self.device_map = kwargs.pop('device_map', None)
|
||||
self.llm_framework = llm_framework
|
||||
# TODO: qwen-int4 need 'cuda'/'auto' device_map.
|
||||
if not self.device_map and 'qwen' in kwargs['model'].lower():
|
||||
self.device_map = 'cuda'
|
||||
|
||||
if os.path.exists(kwargs['model']):
|
||||
config = AutoConfig.from_pretrained(
|
||||
kwargs['model'], trust_remote_code=True)
|
||||
q_config = config.__dict__.get('quantization_config', None)
|
||||
if q_config:
|
||||
if q_config.get(
|
||||
'quant_method',
|
||||
'gptq') == 'gptq' and torch.cuda.device_count():
|
||||
self.device_map = 'cuda'
|
||||
|
||||
self.torch_dtype = kwargs.pop('torch_dtype', None)
|
||||
self.ignore_file_pattern = kwargs.pop('ignore_file_pattern', None)
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ from types import MethodType
|
||||
from typing import Dict, Literal, Optional, Union
|
||||
|
||||
from transformers import AutoConfig as AutoConfigHF
|
||||
from transformers import AutoFeatureExtractor as AutoFeatureExtractorHF
|
||||
from transformers import AutoImageProcessor as AutoImageProcessorHF
|
||||
from transformers import AutoModel as AutoModelHF
|
||||
from transformers import AutoModelForCausalLM as AutoModelForCausalLMHF
|
||||
@@ -14,6 +15,7 @@ from transformers import \
|
||||
AutoModelForSequenceClassification as AutoModelForSequenceClassificationHF
|
||||
from transformers import \
|
||||
AutoModelForTokenClassification as AutoModelForTokenClassificationHF
|
||||
from transformers import AutoProcessor as AutoProcessorHF
|
||||
from transformers import AutoTokenizer as AutoTokenizerHF
|
||||
from transformers import BatchFeature as BatchFeatureHF
|
||||
from transformers import BitsAndBytesConfig as BitsAndBytesConfigHF
|
||||
@@ -161,6 +163,7 @@ def _patch_pretrained_class():
|
||||
ignore_file_pattern, **kwargs)
|
||||
return ori_get_config_dict(cls, model_dir, **kwargs)
|
||||
|
||||
PretrainedConfig.from_pretrained = from_pretrained
|
||||
PretrainedConfig.get_config_dict = get_config_dict
|
||||
|
||||
def patch_model_base():
|
||||
@@ -177,9 +180,54 @@ def _patch_pretrained_class():
|
||||
|
||||
PreTrainedModel.from_pretrained = from_pretrained
|
||||
|
||||
def patch_image_processor_base():
|
||||
""" Monkey patch AutoImageProcessorHF.from_pretrained to adapt to modelscope hub.
|
||||
"""
|
||||
ori_from_pretrained = AutoImageProcessorHF.from_pretrained.__func__
|
||||
|
||||
@classmethod
|
||||
def from_pretrained(cls, pretrained_model_name_or_path, *model_args,
|
||||
**kwargs):
|
||||
model_dir = get_model_dir(pretrained_model_name_or_path, None,
|
||||
**kwargs)
|
||||
return ori_from_pretrained(cls, model_dir, *model_args, **kwargs)
|
||||
|
||||
AutoImageProcessorHF.from_pretrained = from_pretrained
|
||||
|
||||
def patch_auto_processor_base():
|
||||
""" Monkey patch AutoProcessorHF.from_pretrained to adapt to modelscope hub.
|
||||
"""
|
||||
ori_from_pretrained = AutoProcessorHF.from_pretrained.__func__
|
||||
|
||||
@classmethod
|
||||
def from_pretrained(cls, pretrained_model_name_or_path, *model_args,
|
||||
**kwargs):
|
||||
model_dir = get_model_dir(pretrained_model_name_or_path, None,
|
||||
**kwargs)
|
||||
return ori_from_pretrained(cls, model_dir, *model_args, **kwargs)
|
||||
|
||||
AutoProcessorHF.from_pretrained = from_pretrained
|
||||
|
||||
def patch_feature_extractor_base():
|
||||
""" Monkey patch AutoFeatureExtractorHF.from_pretrained to adapt to modelscope hub.
|
||||
"""
|
||||
ori_from_pretrained = AutoFeatureExtractorHF.from_pretrained.__func__
|
||||
|
||||
@classmethod
|
||||
def from_pretrained(cls, pretrained_model_name_or_path, *model_args,
|
||||
**kwargs):
|
||||
model_dir = get_model_dir(pretrained_model_name_or_path, None,
|
||||
**kwargs)
|
||||
return ori_from_pretrained(cls, model_dir, *model_args, **kwargs)
|
||||
|
||||
AutoFeatureExtractorHF.from_pretrained = from_pretrained
|
||||
|
||||
patch_tokenizer_base()
|
||||
patch_config_base()
|
||||
patch_model_base()
|
||||
patch_image_processor_base()
|
||||
patch_auto_processor_base()
|
||||
patch_feature_extractor_base()
|
||||
|
||||
|
||||
def patch_hub():
|
||||
|
||||
@@ -121,7 +121,8 @@ class GeneralMsDatasetTest(unittest.TestCase):
|
||||
f'please check the url: {py_script_url}'
|
||||
|
||||
# Load the dataset
|
||||
ds = MsDataset.load(py_script_file, subset_name='cola', split='train')
|
||||
ds = MsDataset.load(
|
||||
py_script_file, subset_name='cola', split='train')
|
||||
sample = next(iter(ds))
|
||||
logger.info(f'>>output of test_local_py_script:\n {sample}')
|
||||
assert sample
|
||||
|
||||
Reference in New Issue
Block a user