mirror of
https://github.com/modelscope/modelscope.git
synced 2026-09-01 19:49:03 +02:00
fix
This commit is contained in:
@@ -14,6 +14,3 @@ class DownloadDatasetTest(unittest.TestCase):
|
||||
from transformers import AutoModel
|
||||
model = AutoModel.from_pretrained('AI-ModelScope/bert-base-uncased')
|
||||
self.assertTrue(model is not None)
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -2,8 +2,7 @@
|
||||
|
||||
import unittest
|
||||
|
||||
from modelscope import (AutoConfig, AutoModel, AutoModelForCausalLM,
|
||||
AutoTokenizer, GenerationConfig)
|
||||
from modelscope.utils.hf_util.patcher import patch_context
|
||||
|
||||
|
||||
class HFUtilTest(unittest.TestCase):
|
||||
@@ -15,6 +14,7 @@ class HFUtilTest(unittest.TestCase):
|
||||
pass
|
||||
|
||||
def test_auto_tokenizer(self):
|
||||
from modelscope import AutoTokenizer
|
||||
tokenizer = AutoTokenizer.from_pretrained(
|
||||
'baichuan-inc/Baichuan2-7B-Chat',
|
||||
trust_remote_code=True,
|
||||
@@ -28,11 +28,13 @@ class HFUtilTest(unittest.TestCase):
|
||||
self.assertTrue(BitsAndBytesConfig is not None)
|
||||
|
||||
def test_auto_model(self):
|
||||
from modelscope import AutoModelForCausalLM
|
||||
model = AutoModelForCausalLM.from_pretrained(
|
||||
'baichuan-inc/baichuan-7B', trust_remote_code=True)
|
||||
self.assertTrue(model is not None)
|
||||
|
||||
def test_auto_config(self):
|
||||
from modelscope import AutoConfig, GenerationConfig
|
||||
config = AutoConfig.from_pretrained(
|
||||
'baichuan-inc/Baichuan-13B-Chat',
|
||||
trust_remote_code=True,
|
||||
@@ -45,12 +47,63 @@ class HFUtilTest(unittest.TestCase):
|
||||
self.assertEqual(gen_config.assistant_token_id, 196)
|
||||
|
||||
def test_transformer_patch(self):
|
||||
tokenizer = AutoTokenizer.from_pretrained(
|
||||
'iic/nlp_structbert_sentiment-classification_chinese-base')
|
||||
self.assertIsNotNone(tokenizer)
|
||||
model = AutoModelForCausalLM.from_pretrained(
|
||||
'iic/nlp_structbert_sentiment-classification_chinese-base')
|
||||
self.assertIsNotNone(model)
|
||||
with patch_context():
|
||||
from transformers import AutoTokenizer, AutoModelForCausalLM
|
||||
tokenizer = AutoTokenizer.from_pretrained(
|
||||
'iic/nlp_structbert_sentiment-classification_chinese-base')
|
||||
self.assertIsNotNone(tokenizer)
|
||||
model = AutoModelForCausalLM.from_pretrained(
|
||||
'iic/nlp_structbert_sentiment-classification_chinese-base')
|
||||
self.assertIsNotNone(model)
|
||||
|
||||
def test_patch_model(self):
|
||||
from modelscope.utils.hf_util.patcher import patch_context
|
||||
with patch_context():
|
||||
from transformers import AutoModel
|
||||
model = AutoModel.from_pretrained(
|
||||
'iic/nlp_structbert_sentiment-classification_chinese-tiny')
|
||||
self.assertTrue(model is not None)
|
||||
try:
|
||||
model = AutoModel.from_pretrained(
|
||||
'iic/nlp_structbert_sentiment-classification_chinese-tiny')
|
||||
except Exception:
|
||||
pass
|
||||
else:
|
||||
self.assertTrue(False)
|
||||
|
||||
def test_patch_config(self):
|
||||
with patch_context():
|
||||
from transformers import AutoConfig
|
||||
config = AutoConfig.from_pretrained(
|
||||
'iic/nlp_structbert_sentiment-classification_chinese-tiny')
|
||||
self.assertTrue(config is not None)
|
||||
try:
|
||||
config = AutoConfig.from_pretrained(
|
||||
'iic/nlp_structbert_sentiment-classification_chinese-tiny')
|
||||
except Exception:
|
||||
pass
|
||||
else:
|
||||
self.assertTrue(False)
|
||||
|
||||
def test_patch_diffusers(self):
|
||||
with patch_context():
|
||||
from diffusers import StableDiffusionPipeline
|
||||
pipe = StableDiffusionPipeline.from_pretrained(
|
||||
'AI-ModelScope/stable-diffusion-v1-5')
|
||||
self.assertTrue(pipe is not None)
|
||||
try:
|
||||
pipe = StableDiffusionPipeline.from_pretrained(
|
||||
'AI-ModelScope/stable-diffusion-v1-5')
|
||||
except Exception:
|
||||
pass
|
||||
else:
|
||||
self.assertTrue(False)
|
||||
|
||||
def test_patch_peft(self):
|
||||
with patch_context():
|
||||
from peft import PeftModel
|
||||
self.assertTrue(hasattr(PeftModel, '_from_pretrained_origin'))
|
||||
self.assertFalse(hasattr(PeftModel, '_from_pretrained_origin'))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
Reference in New Issue
Block a user