This repository contains the model and weights of the
torch version of Grok-1 open-weights model. You could find a complete example code of using the torch-version Grok-1 in
ColossalAI GitHub Repository. We also applies parallelism techniques from ColossalAI framework (Tensor Parallelism for now) to accelerate the inference.
You could find the original weights released by
xAI in
Hugging Face and the original model in the Grok open release
GitHub Repository.
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.
A transformers-compatible version of tokenizer is contributed by
Xenova and
ArthurZ.
1import torch
2from transformers import AutoModelForCausalLM, AutoTokenizer
3
4torch.set_default_dtype(torch.bfloat16)
5
6tokenizer = AutoTokenizer.from_pretrained("hpcai-tech/grok-1", trust_remote_code=True)
7
8model = AutoModelForCausalLM.from_pretrained(
9 "hpcai-tech/grok-1",
10 trust_remote_code=True,
11 device_map="auto",
12 torch_dtype=torch.bfloat16,
13)
14model.eval()
15
16text = "Replace this with your text"
17input_ids = tokenizer(text, return_tensors="pt").input_ids
18input_ids = input_ids.cuda()
19attention_mask = torch.ones_like(input_ids)
20generate_kwargs = {} # Add any additional args if you want
21inputs = {
22 "input_ids": input_ids,
23 "attention_mask": attention_mask,
24 **generate_kwargs,
25}
26outputs = model.generate(**inputs)
27print(outputs)
Note: A multi-GPU machine is required to test the model with the example code (For now, a 8x80G multi-GPU machine is required).