Instructions to use internlm/JanusCoder-14B with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use internlm/JanusCoder-14B with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="internlm/JanusCoder-14B") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("internlm/JanusCoder-14B") model = AutoModelForCausalLM.from_pretrained("internlm/JanusCoder-14B") messages = [ {"role": "user", "content": "Who are you?"}, ] inputs = tokenizer.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=40) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Inference
- Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use internlm/JanusCoder-14B with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "internlm/JanusCoder-14B" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "internlm/JanusCoder-14B", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/internlm/JanusCoder-14B
- SGLang
How to use internlm/JanusCoder-14B 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 "internlm/JanusCoder-14B" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "internlm/JanusCoder-14B", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'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 "internlm/JanusCoder-14B" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "internlm/JanusCoder-14B", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use internlm/JanusCoder-14B with Docker Model Runner:
docker model run hf.co/internlm/JanusCoder-14B
Fix pipeline_tag π€
#2
by merve HF Staff - opened
README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
---
|
| 2 |
license: apache-2.0
|
| 3 |
-
pipeline_tag:
|
| 4 |
library_name: transformers
|
| 5 |
---
|
| 6 |
|
|
@@ -43,27 +43,33 @@ The following provides demo code illustrating how to generate text using JanusCo
|
|
| 43 |
> Please use transformers >= 4.55.0 to ensure the model works normally.
|
| 44 |
|
| 45 |
```python
|
| 46 |
-
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 47 |
import torch
|
|
|
|
| 48 |
|
| 49 |
model_name = "internlm/JanusCoder-14B"
|
|
|
|
| 50 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 51 |
-
model = AutoModelForCausalLM.from_pretrained(
|
|
|
|
|
|
|
| 52 |
|
| 53 |
messages = [
|
| 54 |
-
{
|
| 55 |
-
"role": "user",
|
| 56 |
-
"content": [
|
| 57 |
-
{"type": "text", "text": "Create a line plot that illustrates function y=x."},
|
| 58 |
-
],
|
| 59 |
-
}
|
| 60 |
]
|
| 61 |
|
| 62 |
-
inputs = tokenizer.apply_chat_template(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
|
| 64 |
-
|
| 65 |
-
decoded_output = processor.decode(generate_ids[0, inputs["input_ids"].shape[1] :], skip_special_tokens=True)
|
| 66 |
-
print(decoded_output)
|
| 67 |
```
|
| 68 |
|
| 69 |
## Citation
|
|
|
|
| 1 |
---
|
| 2 |
license: apache-2.0
|
| 3 |
+
pipeline_tag: text-generation
|
| 4 |
library_name: transformers
|
| 5 |
---
|
| 6 |
|
|
|
|
| 43 |
> Please use transformers >= 4.55.0 to ensure the model works normally.
|
| 44 |
|
| 45 |
```python
|
|
|
|
| 46 |
import torch
|
| 47 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 48 |
|
| 49 |
model_name = "internlm/JanusCoder-14B"
|
| 50 |
+
|
| 51 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 52 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 53 |
+
model_name, device_map="auto", dtype="auto",
|
| 54 |
+
).eval()
|
| 55 |
|
| 56 |
messages = [
|
| 57 |
+
{"role": "user", "content": "Create a line plot that illustrates function y=x."}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
]
|
| 59 |
|
| 60 |
+
inputs = tokenizer.apply_chat_template(
|
| 61 |
+
messages,
|
| 62 |
+
add_generation_prompt=True,
|
| 63 |
+
tokenize=True,
|
| 64 |
+
return_dict=True,
|
| 65 |
+
return_tensors="pt"
|
| 66 |
+
).to(model.device)
|
| 67 |
+
|
| 68 |
+
with torch.inference_mode():
|
| 69 |
+
generate_ids = model.generate(**inputs, max_new_tokens=200)
|
| 70 |
+
decoded_output = tokenizer.batch_decode(generate_ids, skip_special_tokens=True)
|
| 71 |
|
| 72 |
+
print(decoded_output[0])
|
|
|
|
|
|
|
| 73 |
```
|
| 74 |
|
| 75 |
## Citation
|