alvarobartt HF staff commited on
Commit
3ce3d98
1 Parent(s): e9f6887
Files changed (3) hide show
  1. LICENSE +114 -0
  2. README.md +189 -0
  3. USE_POLICY.md +51 -0
LICENSE ADDED
@@ -0,0 +1,114 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ LLAMA 3.1 COMMUNITY LICENSE AGREEMENT
2
+ Llama 3.1 Version Release Date: July 23, 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 Llama 3.1
8
+ distributed by Meta at https://llama.meta.com/doc/overview.
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
+ “Llama 3.1” 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 Llama 3.1 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 (including another AI model) that contains any of them, you shall (A)
41
+ provide a copy of this Agreement with any such Llama Materials; and (B) prominently display “Built with
42
+ Llama” on a related website, user interface, blogpost, about page, or product documentation. If you use
43
+ the Llama Materials or any outputs or results of the Llama Materials to create, train, fine tune, or
44
+ otherwise improve an AI model, which is distributed or made available, you shall also include “Llama” at
45
+ the beginning of any such AI model 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: “Llama 3.1 is
52
+ licensed under the Llama 3.1 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_1/use-policy), which is hereby incorporated by
58
+ reference into this Agreement.
59
+
60
+ 2. Additional Commercial Terms. If, on the Llama 3.1 version release date, the monthly active users
61
+ of the products or services made available by or for Licensee, or Licensee’s affiliates, is greater than 700
62
+ million monthly active users in the preceding calendar month, you must request a license from Meta,
63
+ which Meta may grant to you in its sole discretion, and you are not authorized to exercise any of the
64
+ rights under this Agreement unless or until Meta otherwise expressly grants you such rights.
65
+
66
+ 3. Disclaimer of Warranty. UNLESS REQUIRED BY APPLICABLE LAW, THE LLAMA MATERIALS AND ANY
67
+ OUTPUT AND RESULTS THEREFROM ARE PROVIDED ON AN “AS IS” BASIS, WITHOUT WARRANTIES OF
68
+ ANY KIND, AND META DISCLAIMS ALL WARRANTIES OF ANY KIND, BOTH EXPRESS AND IMPLIED,
69
+ INCLUDING, WITHOUT LIMITATION, ANY WARRANTIES OF TITLE, NON-INFRINGEMENT,
70
+ MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. YOU ARE SOLELY RESPONSIBLE FOR
71
+ DETERMINING THE APPROPRIATENESS OF USING OR REDISTRIBUTING THE LLAMA MATERIALS AND
72
+ ASSUME ANY RISKS ASSOCIATED WITH YOUR USE OF THE LLAMA MATERIALS AND ANY OUTPUT AND
73
+ RESULTS.
74
+
75
+ 4. Limitation of Liability. IN NO EVENT WILL META OR ITS AFFILIATES BE LIABLE UNDER ANY THEORY OF
76
+ LIABILITY, WHETHER IN CONTRACT, TORT, NEGLIGENCE, PRODUCTS LIABILITY, OR OTHERWISE, ARISING
77
+ OUT OF THIS AGREEMENT, FOR ANY LOST PROFITS OR ANY INDIRECT, SPECIAL, CONSEQUENTIAL,
78
+ INCIDENTAL, EXEMPLARY OR PUNITIVE DAMAGES, EVEN IF META OR ITS AFFILIATES HAVE BEEN ADVISED
79
+ OF THE POSSIBILITY OF ANY OF THE FOREGOING.
80
+
81
+ 5. Intellectual Property.
82
+
83
+ a. No trademark licenses are granted under this Agreement, and in connection with the Llama
84
+ Materials, neither Meta nor Licensee may use any name or mark owned by or associated with the other
85
+ or any of its affiliates, except as required for reasonable and customary use in describing and
86
+ redistributing the Llama Materials or as set forth in this Section 5(a). Meta hereby grants you a license to
87
+ use “Llama” (the “Mark”) solely as required to comply with the last sentence of Section 1.b.i. You will
88
+ comply with Meta’s brand guidelines (currently accessible at
89
+ https://about.meta.com/brand/resources/meta/company-brand/ ). All goodwill arising out of your use
90
+ of the Mark will inure to the benefit of Meta.
91
+
92
+ b. Subject to Meta’s ownership of Llama Materials and derivatives made by or for Meta, with
93
+ respect to any derivative works and modifications of the Llama Materials that are made by you, as
94
+ between you and Meta, you are and will be the owner of such derivative works and modifications.
95
+
96
+ c. If you institute litigation or other proceedings against Meta or any entity (including a
97
+ cross-claim or counterclaim in a lawsuit) alleging that the Llama Materials or Llama 3.1 outputs or
98
+ results, or any portion of any of the foregoing, constitutes infringement of intellectual property or other
99
+ rights owned or licensable by you, then any licenses granted to you under this Agreement shall
100
+ terminate as of the date such litigation or claim is filed or instituted. You will indemnify and hold
101
+ harmless Meta from and against any claim by any third party arising out of or related to your use or
102
+ distribution of the Llama Materials.
103
+
104
+ 6. Term and Termination. The term of this Agreement will commence upon your acceptance of this
105
+ Agreement or access to the Llama Materials and will continue in full force and effect until terminated in
106
+ accordance with the terms and conditions herein. Meta may terminate this Agreement if you are in
107
+ breach of any term or condition of this Agreement. Upon termination of this Agreement, you shall delete
108
+ and cease use of the Llama Materials. Sections 3, 4 and 7 shall survive the termination of this
109
+ Agreement.
110
+
111
+ 7. Governing Law and Jurisdiction. This Agreement will be governed and construed under the laws of
112
+ the State of California without regard to choice of law principles, and the UN Convention on Contracts
113
+ for the International Sale of Goods does not apply to this Agreement. The courts of California shall have
114
+ exclusive jurisdiction of any dispute arising out of this Agreement.
README.md ADDED
@@ -0,0 +1,189 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: other
3
+ language:
4
+ - en
5
+ - de
6
+ - fr
7
+ - it
8
+ - pt
9
+ - hi
10
+ - es
11
+ - th
12
+ library_name: transformers
13
+ pipeline_tag: text-generation
14
+ tags:
15
+ - llama-3.1
16
+ - meta
17
+ - autoawq
18
+ ---
19
+
20
+ > [!IMPORTANT]
21
+ > This repository is a community-driven quantized version of the original model [`meta-llama/Meta-Llama-3.1-70B-Instruct`](https://huggingface.co/meta-llama/Meta-Llama-3.1-70B-Instruct) which is the FP16 half-precision official version released by Meta AI.
22
+
23
+ ## Model Information
24
+
25
+ The Meta Llama 3.1 collection of multilingual large language models (LLMs) is a collection of pretrained and instruction tuned generative models in 8B, 70B and 405B sizes (text in/text out). The Llama 3.1 instruction tuned text only models (8B, 70B, 70B) are optimized for multilingual dialogue use cases and outperform many of the available open source and closed chat models on common industry benchmarks.
26
+
27
+ This repository contains [`meta-llama/Meta-Llama-3.1-70B-Instruct`](https://huggingface.co/meta-llama/Meta-Llama-3.1-70B-Instruct) quantized using [AutoAWQ](https://github.com/casperhansen/AutoAWQ) from FP16 down to INT4 using the GEMM kernels performing zero-point quantization with a group size of 128.
28
+
29
+ ## Model Usage
30
+
31
+ > [!NOTE]
32
+ > In order to run the inference with Llama 3.1 70B Instruct AWQ in INT4, around 35 GiB of VRAM are needed only for loading the model checkpoint, without including the KV cache or the CUDA graphs, meaning that there should be a bit over that VRAM available.
33
+
34
+ In order to use the current quantized model, support is offered for different solutions as `transformers`, `autoawq`, or `text-generation-inference`.
35
+
36
+ ### 🤗 transformers
37
+
38
+ In order to run the inference with Llama 3.1 70B Instruct AWQ in INT4, both `torch` and `autoawq` need to be installed as:
39
+
40
+ ```bash
41
+ pip install "torch>=2.2.0,<2.3.0" autoawq --upgrade
42
+ ```
43
+
44
+ Otherwise, running the inference may fail, since the AutoAWQ kernels are built with PyTorch 2.2.1, meaning that those will break with PyTorch 2.3.0.
45
+
46
+ Then, the latest version of `transformers` need to be installed, being 4.43.0 or higher, as:
47
+
48
+ ```bash
49
+ pip install "transformers[accelerate]>=4.43.0" --upgrade
50
+ ```
51
+
52
+ To run the inference on top of Llama 3.1 70B Instruct AWQ in INT4 precision, the AWQ model can be instantiated as any other causal language modeling model via `AutoModelForCausalLM` and run the inference normally.
53
+
54
+ ```python
55
+ import torch
56
+ from transformers import AutoModelForCausalLM, AutoTokenizer
57
+
58
+ model_id = "hugging-quants/Meta-Llama-3.1-70B-Instruct-AWQ-INT4"
59
+ prompt = [
60
+ {"role": "system", "content": "You are a helpful assistant, that responds as a pirate."},
61
+ {"role": "user", "content": "What's Deep Learning?"},
62
+ ]
63
+
64
+ tokenizer = AutoTokenizer.from_pretrained(model_id)
65
+
66
+ inputs = tokenizer.apply_chat_template(
67
+ prompt,
68
+ tokenize=True,
69
+ add_generation_prompt=True,
70
+ return_tensors="pt",
71
+ return_dict=True,
72
+ ).to("cuda")
73
+
74
+ model = AutoModelForCausalLM.from_pretrained(
75
+ model_id,
76
+ torch_dtype=torch.float16,
77
+ low_cpu_mem_usage=True,
78
+ device_map="auto",
79
+ )
80
+
81
+ outputs = model.generate(**inputs, do_sample=True, max_new_tokens=256)
82
+ print(tokenizer.batch_decode(outputs, skip_special_tokens=True))
83
+ ```
84
+
85
+ ### AutoAWQ
86
+
87
+ In order to run the inference with Llama 3.1 70B Instruct AWQ in INT4, both `torch` and `autoawq` need to be installed as:
88
+
89
+ ```bash
90
+ pip install "torch>=2.2.0,<2.3.0" autoawq --upgrade
91
+ ```
92
+
93
+ Otherwise, running the inference may fail, since the AutoAWQ kernels are built with PyTorch 2.2.1, meaning that those will break with PyTorch 2.3.0.
94
+
95
+ Then, the latest version of `transformers` need to be installed, being 4.43.0 or higher, as:
96
+
97
+ ```bash
98
+ pip install "transformers[accelerate]>=4.43.0" --upgrade
99
+ ```
100
+
101
+ Alternatively, one may want to run that via `AutoAWQ` even though it's built on top of 🤗 `transformers`, which is the recommended approach instead as described above.
102
+
103
+ ```python
104
+ import torch
105
+ from autoawq import AutoAWQForCausalLM
106
+ from transformers import AutoModelForCausalLM, AutoTokenizer
107
+
108
+ model_id = "hugging-quants/Meta-Llama-3.1-70B-Instruct-AWQ-INT4"
109
+ prompt = [
110
+ {"role": "system", "content": "You are a helpful assistant, that responds as a pirate."},
111
+ {"role": "user", "content": "What's Deep Learning?"},
112
+ ]
113
+
114
+ tokenizer = AutoTokenizer.from_pretrained(model_id)
115
+
116
+ inputs = tokenizer.apply_chat_template(
117
+ prompt,
118
+ tokenize=True,
119
+ add_generation_prompt=True,
120
+ return_tensors="pt",
121
+ return_dict=True,
122
+ ).to("cuda")
123
+
124
+ model = AutoAWQForCausalLM.from_pretrained(
125
+ model_id,
126
+ torch_dtype=torch.float16,
127
+ low_cpu_mem_usage=True,
128
+ device_map="auto",
129
+ )
130
+
131
+ outputs = model.generate(**inputs, do_sample=True, max_new_tokens=256)
132
+ print(tokenizer.batch_decode(outputs, skip_special_tokens=True))
133
+ ```
134
+
135
+ The AutoAWQ script has been adapted from [AutoAWQ/examples/generate.py](https://github.com/casper-hansen/AutoAWQ/blob/main/examples/generate.py).
136
+
137
+ ### 🤗 Text Generation Inference (TGI)
138
+
139
+ Coming soon!
140
+
141
+ ## Quantization Reproduction
142
+
143
+ > [!NOTE]
144
+ > In order to quantize Llama 3.1 70B Instruct using AutoAWQ, you will need to use an instance with at least enough CPU RAM to fit the whole model i.e. ~140GiB, and an NVIDIA GPU with 40GiB of VRAM to quantize it.
145
+
146
+ In order to quantize Llama 3.1 70B Instruct, first install `torch` and `autoawq` as follows:
147
+
148
+ ```bash
149
+ pip install "torch>=2.2.0,<2.3.0" autoawq --upgrade
150
+ ```
151
+
152
+ Otherwise the quantization may fail, since the AutoAWQ kernels are built with PyTorch 2.2.1, meaning that those will break with PyTorch 2.3.0.
153
+
154
+ Then install the latest version of `transformers` as follows:
155
+
156
+ ```bash
157
+ pip install "transformers>=4.43.0" --upgrade
158
+ ```
159
+
160
+ And then, run the following script, adapted from [`AutoAWQ/examples/quantize.py`](https://github.com/casper-hansen/AutoAWQ/blob/main/examples/quantize.py) as follows:
161
+
162
+ ```python
163
+ from awq import AutoAWQForCausalLM
164
+ from transformers import AutoTokenizer
165
+
166
+ model_path = "meta-llama/Meta-Llama-3.1-70B-Instruct"
167
+ quant_path = "hugging-quants/Meta-Llama-3.1-70B-Instruct-AWQ-INT4"
168
+ quant_config = {
169
+ "zero_point": True,
170
+ "q_group_size": 128,
171
+ "w_bit": 4,
172
+ "version": "GEMM",
173
+ }
174
+
175
+ # Load model
176
+ model = AutoAWQForCausalLM.from_pretrained(
177
+ model_path, **{"low_cpu_mem_usage": True, "use_cache": False}
178
+ )
179
+ tokenizer = AutoTokenizer.from_pretrained(model_path, trust_remote_code=True)
180
+
181
+ # Quantize
182
+ model.quantize(tokenizer, quant_config=quant_config)
183
+
184
+ # Save quantized model
185
+ model.save_quantized(quant_path)
186
+ tokenizer.save_pretrained(quant_path)
187
+
188
+ print(f'Model is quantized and saved at "{quant_path}"')
189
+ ```
USE_POLICY.md ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Llama 3.1 Acceptable Use Policy
2
+
3
+ Meta is committed to promoting safe and fair use of its tools and features, including Llama 3.1. If you
4
+ access or use Llama 3.1, you agree to this Acceptable Use Policy (“Policy”). The most recent copy of
5
+ this policy can be found at [https://llama.meta.com/llama3_1/use-policy](https://llama.meta.com/llama3_1/use-policy)
6
+
7
+ ## Prohibited Uses
8
+
9
+ We want everyone to use Llama 3.1 safely and responsibly. You agree you will not use, or allow
10
+ others to use, Llama 3.1 to:
11
+
12
+ 1. Violate the law or others’ rights, including to:
13
+ 1. Engage in, promote, generate, contribute to, encourage, plan, incite, or further illegal or unlawful activity or content, such as:
14
+ 1. Violence or terrorism
15
+ 2. Exploitation or harm to children, including the solicitation, creation, acquisition, or dissemination of child exploitative content or failure to report Child Sexual Abuse Material
16
+ 3. Human trafficking, exploitation, and sexual violence
17
+ 4. The illegal distribution of information or materials to minors, including obscene materials, or failure to employ legally required age-gating in connection with such information or materials.
18
+ 5. Sexual solicitation
19
+ 6. Any other criminal activity
20
+ 3. Engage in, promote, incite, or facilitate the harassment, abuse, threatening, or bullying of individuals or groups of individuals
21
+ 4. Engage in, promote, incite, or facilitate discrimination or other unlawful or harmful conduct in the provision of employment, employment benefits, credit, housing, other economic benefits, or other essential goods and services
22
+ 5. Engage in the unauthorized or unlicensed practice of any profession including, but not limited to, financial, legal, medical/health, or related professional practices
23
+ 6. Collect, process, disclose, generate, or infer health, demographic, or other sensitive personal or private information about individuals without rights and consents required by applicable laws
24
+ 7. Engage in or facilitate any action or generate any content that infringes, misappropriates, or otherwise violates any third-party rights, including the outputs or results of any products or services using the Llama Materials
25
+ 8. Create, generate, or facilitate the creation of malicious code, malware, computer viruses or do anything else that could disable, overburden, interfere with or impair the proper working, integrity, operation or appearance of a website or computer system
26
+
27
+ 2. Engage in, promote, incite, facilitate, or assist in the planning or development of activities that present a risk of death or bodily harm to individuals, including use of Llama 3.1 related to the following:
28
+ 1. Military, warfare, nuclear industries or applications, espionage, use for materials or activities that are subject to the International Traffic Arms Regulations (ITAR) maintained by the United States Department of State
29
+ 2. Guns and illegal weapons (including weapon development)
30
+ 3. Illegal drugs and regulated/controlled substances
31
+ 4. Operation of critical infrastructure, transportation technologies, or heavy machinery
32
+ 5. Self-harm or harm to others, including suicide, cutting, and eating disorders
33
+ 6. Any content intended to incite or promote violence, abuse, or any infliction of bodily harm to an individual
34
+
35
+ 3. Intentionally deceive or mislead others, including use of Llama 3.1 related to the following:
36
+ 1. Generating, promoting, or furthering fraud or the creation or promotion of disinformation
37
+ 2. Generating, promoting, or furthering defamatory content, including the creation of defamatory statements, images, or other content
38
+ 3. Generating, promoting, or further distributing spam
39
+ 4. Impersonating another individual without consent, authorization, or legal right
40
+ 5. Representing that the use of Llama 3.1 or outputs are human-generated
41
+ 6. Generating or facilitating false online engagement, including fake reviews and other means of fake online engagement
42
+
43
+ 4. Fail to appropriately disclose to end users any known dangers of your AI system
44
+
45
+ Please report any violation of this Policy, software “bug,” or other problems that could lead to a violation
46
+ of this Policy through one of the following means:
47
+
48
+ * Reporting issues with the model: [https://github.com/meta-llama/llama-models/issues](https://github.com/meta-llama/llama-models/issues)
49
+ * Reporting risky content generated by the model: developers.facebook.com/llama_output_feedback
50
+ * Reporting bugs and security concerns: facebook.com/whitehat/info
51
+ * Reporting violations of the Acceptable Use Policy or unlicensed uses of Llama 3.1: [email protected]