fbekeshov commited on
Commit
eca12d4
·
1 Parent(s): c89a54d

Transformers: TildeOpen-30b Space

Browse files
.idea/.gitignore ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ # Default ignored files
2
+ /shelf/
3
+ /workspace.xml
4
+ # Editor-based HTTP Client requests
5
+ /httpRequests/
6
+ # Datasource local storage ignored files
7
+ /dataSources/
8
+ /dataSources.local.xml
.idea/TildeAI.iml ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <module type="PYTHON_MODULE" version="4">
3
+ <component name="NewModuleRootManager">
4
+ <content url="file://$MODULE_DIR$" />
5
+ <orderEntry type="jdk" jdkName="C:\Users\User\miniconda3" jdkType="Python SDK" />
6
+ <orderEntry type="sourceFolder" forTests="false" />
7
+ </component>
8
+ </module>
.idea/inspectionProfiles/profiles_settings.xml ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ <component name="InspectionProjectProfileManager">
2
+ <settings>
3
+ <option name="USE_PROJECT_PROFILE" value="false" />
4
+ <version value="1.0" />
5
+ </settings>
6
+ </component>
.idea/misc.xml ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="Black">
4
+ <option name="sdkName" value="C:\Users\User\miniconda3" />
5
+ </component>
6
+ <component name="ProjectRootManager" version="2" project-jdk-name="C:\Users\User\miniconda3" project-jdk-type="Python SDK" />
7
+ </project>
.idea/modules.xml ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="ProjectModuleManager">
4
+ <modules>
5
+ <module fileurl="file://$PROJECT_DIR$/.idea/TildeAI.iml" filepath="$PROJECT_DIR$/.idea/TildeAI.iml" />
6
+ </modules>
7
+ </component>
8
+ </project>
.idea/vcs.xml ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="VcsDirectoryMappings">
4
+ <mapping directory="" vcs="Git" />
5
+ </component>
6
+ </project>
app.py ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import torch
3
+ from threading import Thread
4
+ from transformers import AutoTokenizer, AutoModelForCausalLM, TextIteratorStreamer
5
+
6
+ MODEL_ID = "TildeAI/TildeOpen-30b"
7
+
8
+ # Tokenizer MUST be slow version per model card
9
+ tokenizer = AutoTokenizer.from_pretrained(MODEL_ID, use_fast=False)
10
+
11
+ # Load model on GPU with BF16
12
+ model = AutoModelForCausalLM.from_pretrained(
13
+ MODEL_ID,
14
+ torch_dtype=torch.bfloat16,
15
+ device_map="auto",
16
+ )
17
+
18
+ SYSTEM = (
19
+ "You are a helpful multilingual assistant. "
20
+ "The model is base (not instruction-tuned), so follow the user's request precisely."
21
+ )
22
+
23
+ def format_history(history, user_msg):
24
+ prompt = SYSTEM + "\n\n"
25
+ for u, a in history:
26
+ prompt += f"<|user|>\n{u}\n<|assistant|>\n{a}\n"
27
+ prompt += f"<|user|>\n{user_msg}\n<|assistant|>\n"
28
+ return prompt
29
+
30
+ def chat_fn(message, history):
31
+ prompt = format_history(history, message)
32
+ inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
33
+
34
+ streamer = TextIteratorStreamer(tokenizer, skip_prompt=True, skip_special_tokens=True)
35
+ gen_kwargs = dict(
36
+ **inputs,
37
+ max_new_tokens=512,
38
+ do_sample=True,
39
+ temperature=0.7,
40
+ top_p=0.9,
41
+ repetition_penalty=1.1,
42
+ streamer=streamer,
43
+ )
44
+
45
+ thread = Thread(target=model.generate, kwargs=gen_kwargs)
46
+ thread.start()
47
+ partial = ""
48
+ for new_text in streamer:
49
+ partial += new_text
50
+ yield partial
51
+
52
+ demo = gr.ChatInterface(
53
+ fn=chat_fn,
54
+ title="TildeOpen-30B (Transformers, BF16)",
55
+ description="Base model (not instruction-tuned). Multilingual; context length 8192.",
56
+ )
57
+ demo.queue().launch()
requirements.txt ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ transformers>=4.44.0
2
+ accelerate>=0.33.0
3
+ safetensors>=0.4.5
4
+ huggingface_hub>=0.24.0
5
+ # Torch GPU: Spaces often has a suitable CUDA. If install fails, remove the next line or switch cu121→cu124.
6
+ torch --index-url https://download.pytorch.org/whl/cu121
7
+ gradio>=4.44.0