Instructions to use OpenMOSS-Team/moss-base-7b with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use OpenMOSS-Team/moss-base-7b with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="OpenMOSS-Team/moss-base-7b", trust_remote_code=True)# Load model directly from transformers import AutoModelForCausalLM model = AutoModelForCausalLM.from_pretrained("OpenMOSS-Team/moss-base-7b", trust_remote_code=True, dtype="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use OpenMOSS-Team/moss-base-7b with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "OpenMOSS-Team/moss-base-7b" # 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-base-7b", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/OpenMOSS-Team/moss-base-7b
- SGLang
How to use OpenMOSS-Team/moss-base-7b 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-base-7b" \ --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-base-7b", "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-base-7b" \ --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-base-7b", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use OpenMOSS-Team/moss-base-7b with Docker Model Runner:
docker model run hf.co/OpenMOSS-Team/moss-base-7b
Fix the code markdown formatting of README
Browse files
README.md
CHANGED
|
@@ -1,20 +1,29 @@
|
|
| 1 |
### Import from Transformers
|
| 2 |
To load the Moss 7B model using Transformers, use the following code:
|
|
|
|
| 3 |
```python
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
郭帆
|
| 15 |
主演分别是吴京和屈楚萧 还有李光洁刘德华等等
|
| 16 |
这电影可以说是目前国内科幻片的天花板了
|
| 17 |
票房也是突破50亿大关啦
|
| 18 |
小编真的非常期待这部电影呀
|
| 19 |
所以呢今天就给大家整理了关于影片中的很多细节图哦~
|
| 20 |
-
不知道大家有没有注意到呢
|
|
|
|
|
|
|
|
|
| 1 |
### Import from Transformers
|
| 2 |
To load the Moss 7B model using Transformers, use the following code:
|
| 3 |
+
|
| 4 |
```python
|
| 5 |
+
# If seeing sentencepiece error: $ pip install sentencepiece
|
| 6 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 7 |
+
tokenizer = AutoTokenizer.from_pretrained("fnlp/moss-base-7b",
|
| 8 |
+
trust_remote_code=True)
|
| 9 |
+
model = AutoModelForCausalLM.from_pretrained("fnlp/moss-base-7b",
|
| 10 |
+
trust_remote_code=True).cuda()
|
| 11 |
+
model = model.eval()
|
| 12 |
+
inputs = tokenizer(["流浪地球的导演是"], return_tensors="pt")
|
| 13 |
+
for k,v in inputs.items():
|
| 14 |
+
inputs[k] = v.cuda()
|
| 15 |
+
outputs = model.generate(**inputs, do_sample=True, temperature=0.8, top_p=0.8,
|
| 16 |
+
repetition_penalty=1.1, max_new_tokens=256)
|
| 17 |
+
response = tokenizer.decode(outputs[0][inputs.input_ids.shape[1]:],
|
| 18 |
+
skip_special_tokens=True)
|
| 19 |
+
print(response)
|
| 20 |
+
"""
|
| 21 |
郭帆
|
| 22 |
主演分别是吴京和屈楚萧 还有李光洁刘德华等等
|
| 23 |
这电影可以说是目前国内科幻片的天花板了
|
| 24 |
票房也是突破50亿大关啦
|
| 25 |
小编真的非常期待这部电影呀
|
| 26 |
所以呢今天就给大家整理了关于影片中的很多细节图哦~
|
| 27 |
+
不知道大家有没有注意到呢
|
| 28 |
+
"""
|
| 29 |
+
```
|