jonathanagustin commited on
Commit
76e3959
1 Parent(s): a1d450d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -82
app.py CHANGED
@@ -1,86 +1,14 @@
1
- # Copyright 2024 X.AI Corp.
2
- #
3
- # Licensed under the Apache License, Version 2.0 (the "License");
4
- # you may not use this file except in compliance with the License.
5
- # You may obtain a copy of the License at
6
- #
7
- # http://www.apache.org/licenses/LICENSE-2.0
8
- #
9
- # Unless required by applicable law or agreed to in writing, software
10
- # distributed under the License is distributed on an "AS IS" BASIS,
11
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- # See the License for the specific language governing permissions and
13
- # limitations under the License.
14
-
15
- import logging
16
- import os
17
-
18
  import gradio as gr
19
- from huggingface_hub import snapshot_download
20
-
21
- from model import LanguageModelConfig
22
- from model import QuantizedWeight8bit as QW8Bit
23
- from model import TransformerConfig
24
- from runners import InferenceRunner, ModelRunner, sample_from_model
25
-
26
- CKPT_PATH = "./checkpoints/"
27
-
28
-
29
- def main():
30
- grok_1_model = LanguageModelConfig(
31
- vocab_size=128 * 1024,
32
- pad_token=0,
33
- eos_token=2,
34
- sequence_len=8192,
35
- embedding_init_scale=1.0,
36
- output_multiplier_scale=0.5773502691896257,
37
- embedding_multiplier_scale=78.38367176906169,
38
- model=TransformerConfig(
39
- emb_size=48 * 128,
40
- widening_factor=8,
41
- key_size=128,
42
- num_q_heads=48,
43
- num_kv_heads=8,
44
- num_layers=64,
45
- attn_output_multiplier=0.08838834764831845,
46
- shard_activations=True,
47
- # MoE.
48
- num_experts=8,
49
- num_selected_experts=2,
50
- # Activation sharding.
51
- data_axis="data",
52
- model_axis="model",
53
- ),
54
- )
55
- inference_runner = InferenceRunner(
56
- pad_sizes=(1024,),
57
- runner=ModelRunner(
58
- model=grok_1_model,
59
- bs_per_device=0.125,
60
- checkpoint_path=CKPT_PATH,
61
- ),
62
- name="local",
63
- load=CKPT_PATH,
64
- tokenizer_path="./tokenizer.model",
65
- local_mesh_config=(1, 8),
66
- between_hosts_config=(1, 1),
67
- )
68
-
69
- inference_runner.initialize()
70
- gen = inference_runner.run()
71
-
72
- def chatbot_response(message, history):
73
- history.append(message)
74
- inp = " ".join(history)
75
- output = sample_from_model(inference_runner.run(), inp, max_len=100, temperature=0.01)
76
- history.append(output)
77
- return output
78
-
79
- iface = gr.ChatInterface(fn=chatbot_response, chatbot="Grok-1", history=[], title="Grok-1")
80
 
81
- iface.launch()
82
 
 
 
 
 
 
 
83
 
84
- if __name__ == "__main__":
85
- logging.basicConfig(level=logging.INFO)
86
- main()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
+ from transformers import pipeline
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
 
4
+ pipe = pipeline("text-generation", model="keyfan/grok-1-hf", trust_remote_code=True)
5
 
6
+ def chatbot_response(message, history):
7
+ history.append(message)
8
+ inp = " ".join(history)
9
+ output = pipe(inp, max_length=100, temperature=0.01)[0]['generated_text'] # Access generated text
10
+ history.append(output)
11
+ return output
12
 
13
+ iface = gr.ChatInterface(fn=chatbot_response, chatbot="Grok-1", history=[], title="Grok-1")
14
+ iface.launch()