Jonathan1909 commited on
Commit
babfc31
1 Parent(s): 55efecd

update README - usage of tokenizer

Browse files
Files changed (1) hide show
  1. README.md +9 -14
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
- The original tokenizer is supposed to be used (i.e. `tokenizer.model` in [GitHub Repository](https://github.com/xai-org/grok-1/tree/main)) with the torch-version model.
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
- sp = SentencePieceProcessor(model_file="tokenizer.model")
34
 
35
  text = "Replace this with your text"
36
- input_ids = sp.encode(text)
37
- input_ids = torch.tensor([input_ids]).cuda()
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