faisalhr1997 teknium commited on
Commit
9be70bc
0 Parent(s):

Duplicate from teknium/sahil2801-replit-code-instruct-glaive

Browse files

Co-authored-by: Teknium <teknium@users.noreply.huggingface.co>

Files changed (4) hide show
  1. .gitattributes +34 -0
  2. README.md +13 -0
  3. app.py +75 -0
  4. requirements.txt +5 -0
.gitattributes ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ *.7z filter=lfs diff=lfs merge=lfs -text
2
+ *.arrow filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.bz2 filter=lfs diff=lfs merge=lfs -text
5
+ *.ckpt filter=lfs diff=lfs merge=lfs -text
6
+ *.ftz filter=lfs diff=lfs merge=lfs -text
7
+ *.gz filter=lfs diff=lfs merge=lfs -text
8
+ *.h5 filter=lfs diff=lfs merge=lfs -text
9
+ *.joblib filter=lfs diff=lfs merge=lfs -text
10
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
+ *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
+ *.model filter=lfs diff=lfs merge=lfs -text
13
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
14
+ *.npy filter=lfs diff=lfs merge=lfs -text
15
+ *.npz filter=lfs diff=lfs merge=lfs -text
16
+ *.onnx filter=lfs diff=lfs merge=lfs -text
17
+ *.ot filter=lfs diff=lfs merge=lfs -text
18
+ *.parquet filter=lfs diff=lfs merge=lfs -text
19
+ *.pb filter=lfs diff=lfs merge=lfs -text
20
+ *.pickle filter=lfs diff=lfs merge=lfs -text
21
+ *.pkl filter=lfs diff=lfs merge=lfs -text
22
+ *.pt filter=lfs diff=lfs merge=lfs -text
23
+ *.pth filter=lfs diff=lfs merge=lfs -text
24
+ *.rar filter=lfs diff=lfs merge=lfs -text
25
+ *.safetensors filter=lfs diff=lfs merge=lfs -text
26
+ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
+ *.tar.* filter=lfs diff=lfs merge=lfs -text
28
+ *.tflite filter=lfs diff=lfs merge=lfs -text
29
+ *.tgz filter=lfs diff=lfs merge=lfs -text
30
+ *.wasm filter=lfs diff=lfs merge=lfs -text
31
+ *.xz filter=lfs diff=lfs merge=lfs -text
32
+ *.zip filter=lfs diff=lfs merge=lfs -text
33
+ *.zst filter=lfs diff=lfs merge=lfs -text
34
+ *tfevents* filter=lfs diff=lfs merge=lfs -text
README.md ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: Replit V1 CodeInstruct 3B
3
+ emoji: 🏢
4
+ colorFrom: red
5
+ colorTo: blue
6
+ sdk: gradio
7
+ sdk_version: 3.32.0
8
+ app_file: app.py
9
+ pinned: false
10
+ duplicated_from: teknium/sahil2801-replit-code-instruct-glaive
11
+ ---
12
+
13
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
app.py ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import gradio as gr
3
+ import torch
4
+
5
+ from transformers import AutoTokenizer, AutoModelForCausalLM
6
+
7
+ REPO = "sahil2801/replit-code-instruct-glaive"
8
+
9
+ description = """# <h1 style="text-align: center; color: white;"><span style='color: #F26207;'> Code Generation by Instruction with sahil2801/replit-code-instruct-glaive </h1>
10
+ <span style="color: white; text-align: center;"> This model is trained on a large amount of code and fine tuned on code-instruct datasets. You can type an instruction in the ### Input: section and received code generation.</span>"""
11
+
12
+ device = "cuda" if torch.cuda.is_available() else "cpu"
13
+
14
+ tokenizer = AutoTokenizer.from_pretrained(REPO, trust_remote_code=True)
15
+ model = AutoModelForCausalLM.from_pretrained(REPO, torch_dtype=torch.bfloat16, trust_remote_code=True)
16
+ model.to(device)
17
+
18
+ model.eval()
19
+
20
+ custom_css = """
21
+ .gradio-container {
22
+ background-color: #0D1525;
23
+ color:white
24
+ }
25
+ #orange-button {
26
+ background: #F26207 !important;
27
+ color: white;
28
+ }
29
+ .cm-gutters{
30
+ border: none !important;
31
+ }
32
+ """
33
+
34
+ def post_processing(prompt, completion):
35
+ return prompt + completion
36
+
37
+ def code_generation(prompt, max_new_tokens=1024, temperature=0.2, top_p=0.9, eos_token_id=tokenizer.eos_token_id):
38
+ input_ids = tokenizer(prompt, return_tensors="pt").input_ids.to(device)
39
+ generated_ids = model.generate(input_ids, max_new_tokens=max_new_tokens, do_sample=True, use_cache=True, temperature=temperature, top_p=top_p, eos_token_id=eos_token_id)
40
+ completion = tokenizer.decode(generated_ids[0][input_ids.shape[-1]:], skip_special_tokens=True, clean_up_tokenization_spaces=False)
41
+ return post_processing(prompt, completion)
42
+
43
+ demo = gr.Blocks(
44
+ css=custom_css
45
+ )
46
+
47
+ with demo:
48
+ gr.Markdown(value=description)
49
+ with gr.Row():
50
+ input_col , settings_col = gr.Column(scale=6), gr.Column(scale=6),
51
+ with input_col:
52
+ code = gr.Code(lines=28,label='Input', value="Below is an instruction that describes a task, paired with an input that provides further context.\n Write a response that appropriately completes the request.\n\n ### Instruction:\nWrite a program to perform the given task.\n\n###Input: \n\n### Response:")
53
+ with settings_col:
54
+ with gr.Accordion("Generation Settings", open=True):
55
+ max_new_tokens= gr.Slider(
56
+ minimum=8,
57
+ maximum=1024,
58
+ step=1,
59
+ value=48,
60
+ label="Max Tokens",
61
+ )
62
+ temperature = gr.Slider(
63
+ minimum=0.1,
64
+ maximum=2.5,
65
+ step=0.1,
66
+ value=0.2,
67
+ label="Temperature",
68
+ )
69
+
70
+ with gr.Row():
71
+ run = gr.Button(elem_id="orange-button", value="Generate Response")
72
+
73
+ event = run.click(code_generation, [code, max_new_tokens, temperature], code, api_name="predict")
74
+
75
+ demo.queue(max_size=40).launch()
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ einops
2
+ sentencepiece
3
+ torch
4
+ transformers
5
+ gradio