Spaces:
Runtime error
Runtime error
sarath-shekkizhar
commited on
Commit
•
45d60f0
1
Parent(s):
26cb129
bfloat16 version uploaded
Browse files
LICENSE
ADDED
@@ -0,0 +1,117 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
META LLAMA 3 COMMUNITY LICENSE AGREEMENT
|
2 |
+
Meta Llama 3 Version Release Date: April 18, 2024
|
3 |
+
|
4 |
+
“Agreement” means the terms and conditions for use, reproduction, distribution and modification of the
|
5 |
+
Llama Materials set forth herein.
|
6 |
+
|
7 |
+
“Documentation” means the specifications, manuals and documentation accompanying Meta Llama 3
|
8 |
+
distributed by Meta at https://llama.meta.com/get-started/.
|
9 |
+
|
10 |
+
“Licensee” or “you” means you, or your employer or any other person or entity (if you are entering into
|
11 |
+
this Agreement on such person or entity’s behalf), of the age required under applicable laws, rules or
|
12 |
+
regulations to provide legal consent and that has legal authority to bind your employer or such other
|
13 |
+
person or entity if you are entering in this Agreement on their behalf.
|
14 |
+
|
15 |
+
“Meta Llama 3” means the foundational large language models and software and algorithms, including
|
16 |
+
machine-learning model code, trained model weights, inference-enabling code, training-enabling code,
|
17 |
+
fine-tuning enabling code and other elements of the foregoing distributed by Meta at
|
18 |
+
https://llama.meta.com/llama-downloads.
|
19 |
+
|
20 |
+
“Llama Materials” means, collectively, Meta’s proprietary Meta Llama 3 and Documentation (and any
|
21 |
+
portion thereof) made available under this Agreement.
|
22 |
+
|
23 |
+
“Meta” or “we” means Meta Platforms Ireland Limited (if you are located in or, if you are an entity, your
|
24 |
+
principal place of business is in the EEA or Switzerland) and Meta Platforms, Inc. (if you are located
|
25 |
+
outside of the EEA or Switzerland).
|
26 |
+
|
27 |
+
By clicking “I Accept” below or by using or distributing any portion or element of the Llama Materials,
|
28 |
+
you agree to be bound by this Agreement.
|
29 |
+
|
30 |
+
1. License Rights and Redistribution.
|
31 |
+
|
32 |
+
a. Grant of Rights. You are granted a non-exclusive, worldwide, non-transferable and royalty-free
|
33 |
+
limited license under Meta’s intellectual property or other rights owned by Meta embodied in the Llama
|
34 |
+
Materials to use, reproduce, distribute, copy, create derivative works of, and make modifications to the
|
35 |
+
Llama Materials.
|
36 |
+
|
37 |
+
b. Redistribution and Use.
|
38 |
+
|
39 |
+
i. If you distribute or make available the Llama Materials (or any derivative works
|
40 |
+
thereof), or a product or service that uses any of them, including another AI model, you shall (A) provide
|
41 |
+
a copy of this Agreement with any such Llama Materials; and (B) prominently display “Built with Meta
|
42 |
+
Llama 3” on a related website, user interface, blogpost, about page, or product documentation. If you
|
43 |
+
use the Llama Materials to create, train, fine tune, or otherwise improve an AI model, which is
|
44 |
+
distributed or made available, you shall also include “Llama 3” at the beginning of any such AI model
|
45 |
+
name.
|
46 |
+
|
47 |
+
ii. If you receive Llama Materials, or any derivative works thereof, from a Licensee as part
|
48 |
+
of an integrated end user product, then Section 2 of this Agreement will not apply to you.
|
49 |
+
|
50 |
+
iii. You must retain in all copies of the Llama Materials that you distribute the following
|
51 |
+
attribution notice within a “Notice” text file distributed as a part of such copies: “Meta Llama 3 is
|
52 |
+
licensed under the Meta Llama 3 Community License, Copyright © Meta Platforms, Inc. All Rights
|
53 |
+
Reserved.”
|
54 |
+
|
55 |
+
iv. Your use of the Llama Materials must comply with applicable laws and regulations
|
56 |
+
(including trade compliance laws and regulations) and adhere to the Acceptable Use Policy for the Llama
|
57 |
+
Materials (available at https://llama.meta.com/llama3/use-policy), which is hereby incorporated by
|
58 |
+
reference into this Agreement.
|
59 |
+
|
60 |
+
v. You will not use the Llama Materials or any output or results of the Llama Materials to
|
61 |
+
improve any other large language model (excluding Meta Llama 3 or derivative works thereof).
|
62 |
+
|
63 |
+
2. Additional Commercial Terms. If, on the Meta Llama 3 version release date, the monthly active users
|
64 |
+
of the products or services made available by or for Licensee, or Licensee’s affiliates, is greater than 700
|
65 |
+
million monthly active users in the preceding calendar month, you must request a license from Meta,
|
66 |
+
which Meta may grant to you in its sole discretion, and you are not authorized to exercise any of the
|
67 |
+
rights under this Agreement unless or until Meta otherwise expressly grants you such rights.
|
68 |
+
|
69 |
+
3. Disclaimer of Warranty. UNLESS REQUIRED BY APPLICABLE LAW, THE LLAMA MATERIALS AND ANY
|
70 |
+
OUTPUT AND RESULTS THEREFROM ARE PROVIDED ON AN “AS IS” BASIS, WITHOUT WARRANTIES OF
|
71 |
+
ANY KIND, AND META DISCLAIMS ALL WARRANTIES OF ANY KIND, BOTH EXPRESS AND IMPLIED,
|
72 |
+
INCLUDING, WITHOUT LIMITATION, ANY WARRANTIES OF TITLE, NON-INFRINGEMENT,
|
73 |
+
MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. YOU ARE SOLELY RESPONSIBLE FOR
|
74 |
+
DETERMINING THE APPROPRIATENESS OF USING OR REDISTRIBUTING THE LLAMA MATERIALS AND
|
75 |
+
ASSUME ANY RISKS ASSOCIATED WITH YOUR USE OF THE LLAMA MATERIALS AND ANY OUTPUT AND
|
76 |
+
RESULTS.
|
77 |
+
|
78 |
+
4. Limitation of Liability. IN NO EVENT WILL META OR ITS AFFILIATES BE LIABLE UNDER ANY THEORY OF
|
79 |
+
LIABILITY, WHETHER IN CONTRACT, TORT, NEGLIGENCE, PRODUCTS LIABILITY, OR OTHERWISE, ARISING
|
80 |
+
OUT OF THIS AGREEMENT, FOR ANY LOST PROFITS OR ANY INDIRECT, SPECIAL, CONSEQUENTIAL,
|
81 |
+
INCIDENTAL, EXEMPLARY OR PUNITIVE DAMAGES, EVEN IF META OR ITS AFFILIATES HAVE BEEN ADVISED
|
82 |
+
OF THE POSSIBILITY OF ANY OF THE FOREGOING.
|
83 |
+
|
84 |
+
5. Intellectual Property.
|
85 |
+
|
86 |
+
a. No trademark licenses are granted under this Agreement, and in connection with the Llama
|
87 |
+
Materials, neither Meta nor Licensee may use any name or mark owned by or associated with the other
|
88 |
+
or any of its affiliates, except as required for reasonable and customary use in describing and
|
89 |
+
redistributing the Llama Materials or as set forth in this Section 5(a). Meta hereby grants you a license to
|
90 |
+
use “Llama 3” (the “Mark”) solely as required to comply with the last sentence of Section 1.b.i. You will
|
91 |
+
comply with Meta’s brand guidelines (currently accessible at
|
92 |
+
https://about.meta.com/brand/resources/meta/company-brand/ ). All goodwill arising out of your use
|
93 |
+
of the Mark will inure to the benefit of Meta.
|
94 |
+
|
95 |
+
b. Subject to Meta’s ownership of Llama Materials and derivatives made by or for Meta, with
|
96 |
+
respect to any derivative works and modifications of the Llama Materials that are made by you, as
|
97 |
+
between you and Meta, you are and will be the owner of such derivative works and modifications.
|
98 |
+
|
99 |
+
c. If you institute litigation or other proceedings against Meta or any entity (including a
|
100 |
+
cross-claim or counterclaim in a lawsuit) alleging that the Llama Materials or Meta Llama 3 outputs or
|
101 |
+
results, or any portion of any of the foregoing, constitutes infringement of intellectual property or other
|
102 |
+
rights owned or licensable by you, then any licenses granted to you under this Agreement shall
|
103 |
+
terminate as of the date such litigation or claim is filed or instituted. You will indemnify and hold
|
104 |
+
harmless Meta from and against any claim by any third party arising out of or related to your use or
|
105 |
+
distribution of the Llama Materials.
|
106 |
+
|
107 |
+
6. Term and Termination. The term of this Agreement will commence upon your acceptance of this
|
108 |
+
Agreement or access to the Llama Materials and will continue in full force and effect until terminated in
|
109 |
+
accordance with the terms and conditions herein. Meta may terminate this Agreement if you are in
|
110 |
+
breach of any term or condition of this Agreement. Upon termination of this Agreement, you shall delete
|
111 |
+
and cease use of the Llama Materials. Sections 3, 4 and 7 shall survive the termination of this
|
112 |
+
Agreement.
|
113 |
+
|
114 |
+
7. Governing Law and Jurisdiction. This Agreement will be governed and construed under the laws of
|
115 |
+
the State of California without regard to choice of law principles, and the UN Convention on Contracts
|
116 |
+
for the International Sale of Goods does not apply to this Agreement. The courts of California shall have
|
117 |
+
exclusive jurisdiction of any dispute arising out of this Agreement.
|
README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
---
|
2 |
title: Llama3 TenyxChat 70B
|
3 |
-
emoji:
|
4 |
-
colorFrom:
|
5 |
colorTo: pink
|
6 |
sdk: gradio
|
7 |
sdk_version: 4.28.3
|
|
|
1 |
---
|
2 |
title: Llama3 TenyxChat 70B
|
3 |
+
emoji: 🐳
|
4 |
+
colorFrom: purple
|
5 |
colorTo: pink
|
6 |
sdk: gradio
|
7 |
sdk_version: 4.28.3
|
app.py
ADDED
@@ -0,0 +1,146 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
from threading import Thread
|
3 |
+
from typing import Iterator
|
4 |
+
|
5 |
+
import gradio as gr
|
6 |
+
import spaces
|
7 |
+
import torch
|
8 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer, TextIteratorStreamer
|
9 |
+
|
10 |
+
MAX_MAX_NEW_TOKENS = 2048
|
11 |
+
DEFAULT_MAX_NEW_TOKENS = 1024
|
12 |
+
MAX_INPUT_TOKEN_LENGTH = int(os.getenv("MAX_INPUT_TOKEN_LENGTH", "4096"))
|
13 |
+
|
14 |
+
DESCRIPTION = """
|
15 |
+
Llama3-TenyxChat-70B is part of the TenyxChat series, models trained to function as useful assistants.
|
16 |
+
The model is obtained via direct preference tuning using Tenyx's fine-tuning technology. Model details available at our model page.
|
17 |
+
|
18 |
+
**The model is currently loaded in bfloat16**.
|
19 |
+
"""
|
20 |
+
|
21 |
+
|
22 |
+
LICENSE = """
|
23 |
+
This demo is governed by the license available [here.](https://huggingface.co/spaces/tenyx/Llama3-TenyxChat-70B/blob/main/LICENSE.txt)"""
|
24 |
+
|
25 |
+
|
26 |
+
if not torch.cuda.is_available():
|
27 |
+
DESCRIPTION += "\n<p>Running on CPU 🥶 This demo does not work on CPU.</p>"
|
28 |
+
|
29 |
+
|
30 |
+
if torch.cuda.is_available():
|
31 |
+
model_id = "tenyx/Llama3-TenyxChat-70B"
|
32 |
+
model = AutoModelForCausalLM.from_pretrained(model_id, device_map="auto", torch_dtype=torch.bfloat16)
|
33 |
+
# model = AutoModelForCausalLM.from_pretrained(model_id, device_map="auto", load_in_8bit=True)
|
34 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
35 |
+
tokenizer.use_default_system_prompt = False
|
36 |
+
|
37 |
+
|
38 |
+
@spaces.GPU
|
39 |
+
def generate(
|
40 |
+
message: str,
|
41 |
+
chat_history: list[tuple[str, str]],
|
42 |
+
system_prompt: str,
|
43 |
+
max_new_tokens: int = 1024,
|
44 |
+
temperature: float = 0.6,
|
45 |
+
top_p: float = 0.9,
|
46 |
+
top_k: int = 50,
|
47 |
+
repetition_penalty: float = 1.2,
|
48 |
+
) -> Iterator[str]:
|
49 |
+
conversation = [{"role": "system", "content": "You are a helpful assistant developed by Tenyx, a conversational voice AI company."}]
|
50 |
+
if system_prompt:
|
51 |
+
conversation.append({"role": "system", "content": system_prompt})
|
52 |
+
for user, assistant in chat_history:
|
53 |
+
conversation.extend([{"role": "user", "content": user}, {"role": "assistant", "content": assistant}])
|
54 |
+
conversation.append({"role": "user", "content": message})
|
55 |
+
|
56 |
+
# if not message.strip():
|
57 |
+
# return "It looks like your message is empty. How can I assist you today?"
|
58 |
+
|
59 |
+
input_ids = tokenizer.apply_chat_template(conversation, add_generation_prompt = True, return_tensors="pt")
|
60 |
+
if input_ids.shape[1] > MAX_INPUT_TOKEN_LENGTH:
|
61 |
+
input_ids = input_ids[:, -MAX_INPUT_TOKEN_LENGTH:]
|
62 |
+
gr.Warning(f"Trimmed input from conversation as it was longer than {MAX_INPUT_TOKEN_LENGTH} tokens.")
|
63 |
+
input_ids = input_ids.to(model.device)
|
64 |
+
|
65 |
+
streamer = TextIteratorStreamer(tokenizer, timeout=10.0, skip_prompt=True, skip_special_tokens=True)
|
66 |
+
generate_kwargs = dict(
|
67 |
+
{"input_ids": input_ids},
|
68 |
+
streamer=streamer,
|
69 |
+
max_new_tokens=max_new_tokens,
|
70 |
+
eos_token_id=[128001, 128009],
|
71 |
+
do_sample=True,
|
72 |
+
top_p=top_p,
|
73 |
+
top_k=top_k,
|
74 |
+
temperature=temperature,
|
75 |
+
num_beams=1,
|
76 |
+
repetition_penalty=repetition_penalty,
|
77 |
+
)
|
78 |
+
t = Thread(target=model.generate, kwargs=generate_kwargs)
|
79 |
+
t.start()
|
80 |
+
|
81 |
+
outputs = []
|
82 |
+
for text in streamer:
|
83 |
+
outputs.append(text)
|
84 |
+
yield "".join(outputs)
|
85 |
+
|
86 |
+
|
87 |
+
chat_interface = gr.ChatInterface(
|
88 |
+
fn=generate,
|
89 |
+
additional_inputs=[
|
90 |
+
gr.Textbox(label="System prompt", lines=6),
|
91 |
+
gr.Slider(
|
92 |
+
label="Max new tokens",
|
93 |
+
minimum=1,
|
94 |
+
maximum=MAX_MAX_NEW_TOKENS,
|
95 |
+
step=1,
|
96 |
+
value=DEFAULT_MAX_NEW_TOKENS,
|
97 |
+
),
|
98 |
+
gr.Slider(
|
99 |
+
label="Temperature",
|
100 |
+
minimum=0.1,
|
101 |
+
maximum=4.0,
|
102 |
+
step=0.1,
|
103 |
+
value=0.1,
|
104 |
+
),
|
105 |
+
gr.Slider(
|
106 |
+
label="Top-p (nucleus sampling)",
|
107 |
+
minimum=0.05,
|
108 |
+
maximum=1.0,
|
109 |
+
step=0.05,
|
110 |
+
value=0.9,
|
111 |
+
),
|
112 |
+
gr.Slider(
|
113 |
+
label="Top-k",
|
114 |
+
minimum=1,
|
115 |
+
maximum=1000,
|
116 |
+
step=1,
|
117 |
+
value=50,
|
118 |
+
),
|
119 |
+
gr.Slider(
|
120 |
+
label="Repetition penalty",
|
121 |
+
minimum=1.0,
|
122 |
+
maximum=2.0,
|
123 |
+
step=0.05,
|
124 |
+
value=1.2,
|
125 |
+
),
|
126 |
+
],
|
127 |
+
stop_btn=None,
|
128 |
+
examples=[
|
129 |
+
["Hello there! How are you doing?"],
|
130 |
+
["Can you explain briefly to me what is the Python programming language?"],
|
131 |
+
["Explain the potential role of Conversational AIs in customer support."],
|
132 |
+
["How many hours does it take a man to eat a Helicopter?"],
|
133 |
+
["Write a 100-word article on 'Benefits of Open-Source in AI research'"],
|
134 |
+
],
|
135 |
+
)
|
136 |
+
|
137 |
+
with gr.Blocks(css="style.css") as demo:
|
138 |
+
gr.Markdown(DESCRIPTION)
|
139 |
+
gr.DuplicateButton(value="Duplicate Space for private use", elem_id="duplicate-button")
|
140 |
+
chat_interface.render()
|
141 |
+
gr.Markdown(LICENSE)
|
142 |
+
|
143 |
+
if __name__ == "__main__":
|
144 |
+
demo.queue(max_size=4).launch()
|
145 |
+
|
146 |
+
|
requirements.txt
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
accelerate==0.29.3
|
2 |
+
bitsandbytes==0.41.2.post2
|
3 |
+
gradio==4.28.3
|
4 |
+
protobuf==3.20.2
|
5 |
+
spaces==0.26.2
|
6 |
+
torch==2.3.0
|
7 |
+
transformers==4.40.1
|