Instructions to use OpenMOSS-Team/moss-moon-003-sft-int4 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use OpenMOSS-Team/moss-moon-003-sft-int4 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="OpenMOSS-Team/moss-moon-003-sft-int4", trust_remote_code=True)# Load model directly from transformers import AutoModelForCausalLM model = AutoModelForCausalLM.from_pretrained("OpenMOSS-Team/moss-moon-003-sft-int4", trust_remote_code=True, dtype="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use OpenMOSS-Team/moss-moon-003-sft-int4 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "OpenMOSS-Team/moss-moon-003-sft-int4" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "OpenMOSS-Team/moss-moon-003-sft-int4", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/OpenMOSS-Team/moss-moon-003-sft-int4
- SGLang
How to use OpenMOSS-Team/moss-moon-003-sft-int4 with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "OpenMOSS-Team/moss-moon-003-sft-int4" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "OpenMOSS-Team/moss-moon-003-sft-int4", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "OpenMOSS-Team/moss-moon-003-sft-int4" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "OpenMOSS-Team/moss-moon-003-sft-int4", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use OpenMOSS-Team/moss-moon-003-sft-int4 with Docker Model Runner:
docker model run hf.co/OpenMOSS-Team/moss-moon-003-sft-int4
Single GPU时:No module named 'transformers_modules.moss-moon-003-sft-int4.custom_autotune'
#4
by xiabo0816 - opened
root@bogon ~/m/MOSS (main)# python3
Python 3.9.16 (main, Mar 8 2023, 14:00:05)
[GCC 11.2.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from transformers import AutoTokenizer, AutoModelForCausalLM
>>> tokenizer = AutoTokenizer.from_pretrained("/root/moss/moss-moon-003-sft-int4", trust_remote_code=True)
Explicitly passing a `revision` is encouraged when loading a model with custom code to ensure no malicious code has been contributed in a newer revision.
>>> model = AutoModelForCausalLM.from_pretrained("/root/moss/moss-moon-003-sft-int4", trust_remote_code=True).half().cuda()
Explicitly passing a `revision` is encouraged when loading a configuration with custom code to ensure no malicious code has been contributed in a newer revision.
Explicitly passing a `revision` is encouraged when loading a model with custom code to ensure no malicious code has been contributed in a newer revision.
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/root/miniconda3/envs/chatglm/lib/python3.9/site-packages/transformers/models/auto/auto_factory.py", line 466, in from_pretrained
return model_class.from_pretrained(
File "/root/miniconda3/envs/chatglm/lib/python3.9/site-packages/transformers/modeling_utils.py", line 2498, in from_pretrained
model = cls(config, *model_args, **model_kwargs)
File "/root/.cache/huggingface/modules/transformers_modules/moss-moon-003-sft-int4/modeling_moss.py", line 608, in __init__
self.quantize(config.wbits, config.groupsize)
File "/root/.cache/huggingface/modules/transformers_modules/moss-moon-003-sft-int4/modeling_moss.py", line 732, in quantize
from .quantization import quantize_with_gptq
File "/root/.cache/huggingface/modules/transformers_modules/moss-moon-003-sft-int4/quantization.py", line 8, in <module>
from .custom_autotune import *
ModuleNotFoundError: No module named 'transformers_modules.moss-moon-003-sft-int4.custom_autotune'
>
已经git clone 过MOSS.git,也cd进来,还是报:
ModuleNotFoundError: No module named 'transformers_modules.moss-moon-003-sft-int4.custom_autotune'
是仍然有文件放错位置了吗?
在多加了一个斜线/之后:
model = AutoModelForCausalLM.from_pretrained("/root/moss/moss-moon-003-sft-int4/", trust_remote_code=True).half().cuda()
报错改变了:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/root/miniconda3/envs/chatglm/lib/python3.9/site-packages/transformers/models/auto/auto_factory.py", line 466, in from_pretrained
return model_class.from_pretrained(
File "/root/miniconda3/envs/chatglm/lib/python3.9/site-packages/transformers/modeling_utils.py", line 2498, in from_pretrained
model = cls(config, *model_args, **model_kwargs)
File "/root/.cache/huggingface/modules/transformers_modules/modeling_moss.py", line 608, in __init__
self.quantize(config.wbits, config.groupsize)
File "/root/.cache/huggingface/modules/transformers_modules/modeling_moss.py", line 732, in quantize
from .quantization import quantize_with_gptq
File "/root/.cache/huggingface/modules/transformers_modules/quantization.py", line 8, in <module>
from .custom_autotune import *
ModuleNotFoundError: No module named 'transformers_modules.custom_autotune'
Same error
我直接把 custom_autotune.py Copy到"/root/.cache/huggingface/modules/transformers_modules/"
试试这个
import sys
sys.path.append('/root/.cache/huggingface/modules')
我用的是Tesla P40,换成fnlp/moss-moon-003-sft就很正常了,感觉是显卡和INT4不太搭?
试试这个
import sys sys.path.append('/root/.cache/huggingface/modules')
我这里尝试了之后,还是不行😢
我直接把 custom_autotune.py Copy到"/root/.cache/huggingface/modules/transformers_modules/"
我这里尝试了之后,也还是不行
我直接把 custom_autotune.py Copy到"/root/.cache/huggingface/modules/transformers_modules/"
我这里尝试了之后,也还是不行