Instructions to use hpcai-tech/grok-1 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use hpcai-tech/grok-1 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="hpcai-tech/grok-1", trust_remote_code=True)# Load model directly from transformers import AutoModelForCausalLM model = AutoModelForCausalLM.from_pretrained("hpcai-tech/grok-1", trust_remote_code=True, dtype="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use hpcai-tech/grok-1 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "hpcai-tech/grok-1" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "hpcai-tech/grok-1", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/hpcai-tech/grok-1
- SGLang
How to use hpcai-tech/grok-1 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 "hpcai-tech/grok-1" \ --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": "hpcai-tech/grok-1", "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 "hpcai-tech/grok-1" \ --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": "hpcai-tech/grok-1", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use hpcai-tech/grok-1 with Docker Model Runner:
docker model run hf.co/hpcai-tech/grok-1
Commit ·
babfc31
1
Parent(s): 55efecd
update README - usage of tokenizer
Browse files
README.md
CHANGED
|
@@ -14,27 +14,29 @@ You could find the original weights released by [xAI](https://x.ai/blog) in [Hug
|
|
| 14 |
|
| 15 |
We translated the original modeling written in JAX into PyTorch version, and converted the weights by mapping tensor files with parameter keys, de-quantizing the tensors with corresponding packed scales, and save to checkpoint file with torch APIs.
|
| 16 |
|
| 17 |
-
|
| 18 |
|
| 19 |
## Usage
|
| 20 |
|
| 21 |
```python
|
| 22 |
import torch
|
| 23 |
-
from transformers import AutoModelForCausalLM
|
| 24 |
-
from sentencepiece import SentencePieceProcessor
|
| 25 |
|
| 26 |
torch.set_default_dtype(torch.bfloat16)
|
|
|
|
|
|
|
|
|
|
| 27 |
model = AutoModelForCausalLM.from_pretrained(
|
| 28 |
"hpcai-tech/grok-1",
|
| 29 |
trust_remote_code=True,
|
| 30 |
device_map="auto",
|
| 31 |
torch_dtype=torch.bfloat16,
|
| 32 |
)
|
| 33 |
-
|
| 34 |
|
| 35 |
text = "Replace this with your text"
|
| 36 |
-
input_ids =
|
| 37 |
-
input_ids =
|
| 38 |
attention_mask = torch.ones_like(input_ids)
|
| 39 |
generate_kwargs = {} # Add any additional args if you want
|
| 40 |
inputs = {
|
|
@@ -43,14 +45,7 @@ inputs = {
|
|
| 43 |
**generate_kwargs,
|
| 44 |
}
|
| 45 |
outputs = model.generate(**inputs)
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
You could also use the transformers-compatible version of the tokenizer [Xenova/grok-1-tokenizer](https://huggingface.co/Xenova/grok-1-tokenizer)
|
| 49 |
-
```python
|
| 50 |
-
from transformers import LlamaTokenizerFast
|
| 51 |
-
|
| 52 |
-
tokenizer = LlamaTokenizerFast.from_pretrained('Xenova/grok-1-tokenizer')
|
| 53 |
-
inputs = tokenizer('hello world')
|
| 54 |
```
|
| 55 |
|
| 56 |
|
|
|
|
| 14 |
|
| 15 |
We translated the original modeling written in JAX into PyTorch version, and converted the weights by mapping tensor files with parameter keys, de-quantizing the tensors with corresponding packed scales, and save to checkpoint file with torch APIs.
|
| 16 |
|
| 17 |
+
A transformers-compatible version of tokenizer is contributed by [Xenova](https://huggingface.co/Xenova) and [ArthurZ](https://huggingface.co/ArthurZ).
|
| 18 |
|
| 19 |
## Usage
|
| 20 |
|
| 21 |
```python
|
| 22 |
import torch
|
| 23 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
|
|
|
| 24 |
|
| 25 |
torch.set_default_dtype(torch.bfloat16)
|
| 26 |
+
|
| 27 |
+
tokenizer = AutoTokenizer.from_pretrained("hpcai-tech/grok-1", trust_remote_code=True)
|
| 28 |
+
|
| 29 |
model = AutoModelForCausalLM.from_pretrained(
|
| 30 |
"hpcai-tech/grok-1",
|
| 31 |
trust_remote_code=True,
|
| 32 |
device_map="auto",
|
| 33 |
torch_dtype=torch.bfloat16,
|
| 34 |
)
|
| 35 |
+
model.eval()
|
| 36 |
|
| 37 |
text = "Replace this with your text"
|
| 38 |
+
input_ids = tokenizer(text, return_tensors="pt").input_ids
|
| 39 |
+
input_ids = input_ids.cuda()
|
| 40 |
attention_mask = torch.ones_like(input_ids)
|
| 41 |
generate_kwargs = {} # Add any additional args if you want
|
| 42 |
inputs = {
|
|
|
|
| 45 |
**generate_kwargs,
|
| 46 |
}
|
| 47 |
outputs = model.generate(**inputs)
|
| 48 |
+
print(outputs)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
```
|
| 50 |
|
| 51 |
|