Commit
•
51daf1f
1
Parent(s):
7eb6642
Create README.md (#1)
Browse files- Create README.md (3cb7941212071bb19f024036bc9426e56d3a14f3)
- Create USE_POLICY.md (b0cb46340e0210ff0018b8f6e620f0a2f68f8826)
- Create LICENSE (5db020111bae4a7bd74f3b89c732090ff2ceeab4)
- Update README.md (3de3f011dba8f5b616df4edc5381aa70cf6e2c74)
- LICENSE +114 -0
- README.md +231 -0
- 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,231 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
- autogptq
|
18 |
+
---
|
19 |
+
|
20 |
+
> [!IMPORTANT]
|
21 |
+
> This repository is a community-driven quantized version of the original model [`meta-llama/Meta-Llama-3.1-405B-Instruct`](https://huggingface.co/meta-llama/Meta-Llama-3.1-405B-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, 405B) 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-405B-Instruct`](https://huggingface.co/meta-llama/Meta-Llama-3.1-405B-Instruct) quantized using [AutoGPTQ](https://github.com/AutoGPTQ/AutoGPTQ) from FP16 down to INT4 using the GPTQ 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 405B Instruct GPTQ in INT4, around 203 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`, `autogptq`, or `text-generation-inference`.
|
35 |
+
|
36 |
+
### 🤗 transformers
|
37 |
+
|
38 |
+
In order to run the inference with Llama 3.1 405B Instruct GPTQ in INT4, both `torch` and `autogptq` need to be installed as:
|
39 |
+
|
40 |
+
```bash
|
41 |
+
pip install "torch>=2.2.0,<2.3.0" --upgrade
|
42 |
+
pip install auto-gptq --no-build-isolation
|
43 |
+
```
|
44 |
+
|
45 |
+
Otherwise, running the model may fail, since the AutoGPTQ kernels are built with PyTorch 2.2.1, meaning that those will break with PyTorch 2.3.0.
|
46 |
+
|
47 |
+
Then, the latest version of `transformers` need to be installed including the `accelerate` extra, being 4.43.0 or higher, as:
|
48 |
+
|
49 |
+
```bash
|
50 |
+
pip install "transformers[accelerate]>=4.43.0" --upgrade
|
51 |
+
```
|
52 |
+
|
53 |
+
Finally, in order to use `autogptq`, `optimum` also needs to be installed:
|
54 |
+
|
55 |
+
```bash
|
56 |
+
pip install optimum --upgrade
|
57 |
+
```
|
58 |
+
|
59 |
+
To run the inference on top of Llama 3.1 405B Instruct GPTQ in INT4 precision, the GPTQ model can be instantiated as any other causal language modeling model via `AutoModelForCausalLM` and run the inference normally.
|
60 |
+
|
61 |
+
```python
|
62 |
+
import torch
|
63 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
64 |
+
|
65 |
+
model_id = "hugging-quants/Meta-Llama-3.1-405B-Instruct-GPTQ-INT4"
|
66 |
+
prompt = [
|
67 |
+
{"role": "system", "content": "You are a helpful assistant, that responds as a pirate."},
|
68 |
+
{"role": "user", "content": "What's Deep Learning?"},
|
69 |
+
]
|
70 |
+
|
71 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
72 |
+
|
73 |
+
inputs = tokenizer.apply_chat_template(
|
74 |
+
prompt,
|
75 |
+
tokenize=True,
|
76 |
+
add_generation_prompt=True,
|
77 |
+
return_tensors="pt",
|
78 |
+
return_dict=True,
|
79 |
+
).to("cuda")
|
80 |
+
|
81 |
+
model = AutoModelForCausalLM.from_pretrained(
|
82 |
+
model_id,
|
83 |
+
torch_dtype=torch.float16,
|
84 |
+
low_cpu_mem_usage=True,
|
85 |
+
device_map="auto",
|
86 |
+
)
|
87 |
+
|
88 |
+
outputs = model.generate(**inputs, do_sample=True, max_new_tokens=256)
|
89 |
+
print(tokenizer.batch_decode(outputs, skip_special_tokens=True))
|
90 |
+
```
|
91 |
+
|
92 |
+
### AutoGPTQ
|
93 |
+
|
94 |
+
Alternatively, one may want to run that via `AutoGPTQ` even though it's built on top of 🤗 `transformers`, which is the recommended approach instead as described above.
|
95 |
+
|
96 |
+
In order to run the inference with Llama 3.1 405B Instruct GPTQ in INT4, both `torch` and `autogptq` need to be installed as:
|
97 |
+
|
98 |
+
```bash
|
99 |
+
pip install "torch>=2.2.0,<2.3.0" --upgrade
|
100 |
+
pip install auto-gptq --no-build-isolation
|
101 |
+
```
|
102 |
+
|
103 |
+
Otherwise, running the model may fail, since the AutoGPTQ kernels are built with PyTorch 2.2.1, meaning that those will break with PyTorch 2.3.0.
|
104 |
+
|
105 |
+
Then, the latest version of `transformers` need to be installed including the `accelerate` extra, being 4.43.0 or higher, as:
|
106 |
+
|
107 |
+
```bash
|
108 |
+
pip install "transformers[accelerate]>=4.43.0" --upgrade
|
109 |
+
```
|
110 |
+
|
111 |
+
Finally, in order to use `autogptq`, `optimum` also needs to be installed:
|
112 |
+
|
113 |
+
```bash
|
114 |
+
pip install optimum --upgrade
|
115 |
+
```
|
116 |
+
|
117 |
+
And then run it as follows:
|
118 |
+
|
119 |
+
```python
|
120 |
+
import torch
|
121 |
+
from auto_gptq import AutoGPTQForCausalLM
|
122 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
123 |
+
|
124 |
+
model_id = "hugging-quants/Meta-Llama-3.1-405B-Instruct-GPTQ-INT4"
|
125 |
+
prompt = [
|
126 |
+
{"role": "system", "content": "You are a helpful assistant, that responds as a pirate."},
|
127 |
+
{"role": "user", "content": "What's Deep Learning?"},
|
128 |
+
]
|
129 |
+
|
130 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
131 |
+
|
132 |
+
inputs = tokenizer.apply_chat_template(prompt, tokenize=True, add_generation_prompt=True, return_tensors="pt").cuda()
|
133 |
+
|
134 |
+
model = AutoGPTQForCausalLM.from_pretrained(
|
135 |
+
model_id,
|
136 |
+
torch_dtype=torch.float16,
|
137 |
+
low_cpu_mem_usage=True,
|
138 |
+
device_map="auto",
|
139 |
+
)
|
140 |
+
|
141 |
+
outputs = model.generate(inputs, do_sample=True, max_new_tokens=256)
|
142 |
+
print(tokenizer.batch_decode(outputs, skip_special_tokens=True))
|
143 |
+
```
|
144 |
+
|
145 |
+
The AutoGPTQ script has been adapted from [AutoGPTQ/examples/quantization/basic_usage.py](https://github.com/AutoGPTQ/AutoGPTQ/blob/main/examples/quantization/basic_usage.py).
|
146 |
+
|
147 |
+
### 🤗 Text Generation Inference (TGI)
|
148 |
+
|
149 |
+
Coming soon!
|
150 |
+
|
151 |
+
## Quantization Reproduction
|
152 |
+
|
153 |
+
> [!NOTE]
|
154 |
+
> In order to quantize Llama 3.1 405B Instruct using AutoGPTQ, you will need to use an instance with at least enough CPU RAM to fit the whole model i.e. ~800GiB, and an NVIDIA GPU with 80GiB of VRAM to quantize it.
|
155 |
+
|
156 |
+
In order to quantize Llama 3.1 405B Instruct, first install `torch` and `autoqptq` as follows:
|
157 |
+
|
158 |
+
```bash
|
159 |
+
pip install "torch>=2.2.0,<2.3.0" --upgrade
|
160 |
+
pip install auto-gptq --no-build-isolation
|
161 |
+
```
|
162 |
+
|
163 |
+
Otherwise the quantization may fail, since the AutoGPTQ kernels are built with PyTorch 2.2.1, meaning that those will break with PyTorch 2.3.0.
|
164 |
+
|
165 |
+
Then install the latest version of `transformers` as follows:
|
166 |
+
|
167 |
+
```bash
|
168 |
+
pip install "transformers>=4.43.0" --upgrade
|
169 |
+
```
|
170 |
+
|
171 |
+
Finally, in order to use `autogptq`, `optimum` also needs to be installed:
|
172 |
+
|
173 |
+
```bash
|
174 |
+
pip install optimum --upgrade
|
175 |
+
```
|
176 |
+
|
177 |
+
And then, run the following script, adapted from [AutoGPTQ/examples/quantization/basic_usage.py](https://github.com/AutoGPTQ/AutoGPTQ/blob/main/examples/quantization/basic_usage.py).
|
178 |
+
|
179 |
+
```python
|
180 |
+
import random
|
181 |
+
|
182 |
+
import numpy as np
|
183 |
+
import torch
|
184 |
+
|
185 |
+
from auto_gptq import AutoGPTQForCausalLM, BaseQuantizeConfig
|
186 |
+
from datasets import load_dataset
|
187 |
+
from transformers import AutoTokenizer
|
188 |
+
|
189 |
+
pretrained_model_dir = "meta-llama/Meta-Llama-3.1-405B-Instruct"
|
190 |
+
quantized_model_dir = "meta-llama/Meta-Llama-3.1-405B-Instruct-GPTQ-INT4"
|
191 |
+
|
192 |
+
print("Loading tokenizer, dataset, and tokenizing the dataset...")
|
193 |
+
tokenizer = AutoTokenizer.from_pretrained(pretrained_model_dir, use_fast=True)
|
194 |
+
dataset = load_dataset("Salesforce/wikitext", "wikitext-2-raw-v1", split="train")
|
195 |
+
encodings = tokenizer("\n\n".join(dataset["text"]), return_tensors="pt")
|
196 |
+
|
197 |
+
print("Setting random seeds...")
|
198 |
+
random.seed(0)
|
199 |
+
np.random.seed(0)
|
200 |
+
torch.random.manual_seed(0)
|
201 |
+
|
202 |
+
print("Setting calibration samples...")
|
203 |
+
nsamples = 128
|
204 |
+
seqlen = 2048
|
205 |
+
calibration_samples = []
|
206 |
+
for _ in range(nsamples):
|
207 |
+
i = random.randint(0, encodings.input_ids.shape[1] - seqlen - 1)
|
208 |
+
j = i + seqlen
|
209 |
+
input_ids = encodings.input_ids[:, i:j]
|
210 |
+
attention_mask = torch.ones_like(input_ids)
|
211 |
+
calibration_samples.append({"input_ids": input_ids, "attention_mask": attention_mask})
|
212 |
+
|
213 |
+
quantize_config = BaseQuantizeConfig(
|
214 |
+
bits=4, # quantize model to 4-bit
|
215 |
+
group_size=128, # it is recommended to set the value to 128
|
216 |
+
desc_act=True, # set to False can significantly speed up inference but the perplexity may slightly bad
|
217 |
+
sym=True, # using symmetric quantization so that the range is symmetric allowing the value 0 to be precisely represented (can provide speedups)
|
218 |
+
damp_percent=0.1, # see https://github.com/AutoGPTQ/AutoGPTQ/issues/196
|
219 |
+
)
|
220 |
+
|
221 |
+
# load un-quantized model, by default, the model will always be loaded into CPU memory
|
222 |
+
print("Load unquantized model...")
|
223 |
+
model = AutoGPTQForCausalLM.from_pretrained(pretrained_model_dir, quantize_config)
|
224 |
+
|
225 |
+
# quantize model, the examples should be list of dict whose keys can only be "input_ids" and "attention_mask"
|
226 |
+
print("Quantize model with calibration samples...")
|
227 |
+
model.quantize(calibration_samples)
|
228 |
+
|
229 |
+
# save quantized model using safetensors
|
230 |
+
model.save_quantized(quantized_model_dir, use_safetensors=True)
|
231 |
+
```
|
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]
|