Duplicate from PygmalionAI/pygmalion-7b
Browse filesCo-authored-by: 0x000011b <[email protected]>
- .gitattributes +3 -0
- README.md +83 -0
- xor_codec.py +92 -0
- xor_encoded_files/config.json +3 -0
- xor_encoded_files/generation_config.json +3 -0
- xor_encoded_files/pytorch_model-00001-of-00002.bin +3 -0
- xor_encoded_files/pytorch_model-00002-of-00002.bin +3 -0
- xor_encoded_files/pytorch_model.bin.index.json +3 -0
- xor_encoded_files/special_tokens_map.json +3 -0
- xor_encoded_files/tokenizer.json +3 -0
- xor_encoded_files/tokenizer.model +3 -0
- xor_encoded_files/tokenizer_config.json +3 -0
.gitattributes
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
2 |
+
*.json filter=lfs diff=lfs merge=lfs -text
|
3 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
README.md
ADDED
@@ -0,0 +1,83 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
language:
|
3 |
+
- en
|
4 |
+
thumbnail: null
|
5 |
+
tags:
|
6 |
+
- text generation
|
7 |
+
- conversational
|
8 |
+
pipeline_tag: text-generation
|
9 |
+
inference: false
|
10 |
+
---
|
11 |
+
<h1 style="text-align: center">Pygmalion 7B</h1>
|
12 |
+
<h2 style="text-align: center">A conversational LLaMA fine-tune.</h2>
|
13 |
+
|
14 |
+
## Model Details
|
15 |
+
|
16 |
+
Pygmalion 7B is a dialogue model based on Meta's LLaMA-7B.
|
17 |
+
|
18 |
+
This is version 1. It has been fine-tuned using a subset of the data from Pygmalion-6B-v8-pt4, for those of you familiar with the project.
|
19 |
+
|
20 |
+
## Applying the XORs
|
21 |
+
|
22 |
+
**The model weights in this repository cannot be used as-is.** The files here are XORs due to licensing concerns. To obtain proper, usable model weights you need to:
|
23 |
+
|
24 |
+
- Request access to the original LLaMA weights from Meta [through this form](https://docs.google.com/forms/d/e/1FAIpQLSfqNECQnMkycAp2jP4Z9TFX0cGR4uf7b_fBxjY_OjhJILlKGA/viewform?usp=send_form)
|
25 |
+
- Convert them to the HuggingFace Transformers format by using the [convert_llama_weights_to_hf.py](https://github.com/huggingface/transformers/blob/849367ccf741d8c58aa88ccfe1d52d8636eaf2b7/src/transformers/models/llama/convert_llama_weights_to_hf.py) script **for your version of the `transformers` library**
|
26 |
+
- With the LLaMA-7B weights in hand, you can use the [xor_codec.py](./xor_codec.py) script provided in this repository:
|
27 |
+
|
28 |
+
```bash
|
29 |
+
python3 xor_codec.py \
|
30 |
+
./pygmalion-7b \
|
31 |
+
./xor_encoded_files \
|
32 |
+
/path/to/hf-converted/llama-7b \
|
33 |
+
--decode
|
34 |
+
```
|
35 |
+
|
36 |
+
```bash
|
37 |
+
$ rhash -M *
|
38 |
+
4608facb4910118f8dfa80f090cbc4dc config.json
|
39 |
+
2917a1cafb895cf57e746cfd7696bfe5 generation_config.json
|
40 |
+
98764eb949eea16f8e2e1c2d3dea0066 pytorch_model-00001-of-00002.bin
|
41 |
+
be9ba2f37228a0a9ea0eaf6530aba4de pytorch_model-00002-of-00002.bin
|
42 |
+
81648ef3915ed2e83d49fed93122d53e pytorch_model.bin.index.json
|
43 |
+
6b2e0a735969660e720c27061ef3f3d3 special_tokens_map.json
|
44 |
+
fdb311c39b8659a5d5c1991339bafc09 tokenizer.json
|
45 |
+
eeec4125e9c7560836b4873b6f8e3025 tokenizer.model
|
46 |
+
9b3cf7b8c0e4783dbc1419b4cafe8e1e tokenizer_config.json
|
47 |
+
```
|
48 |
+
|
49 |
+
## Prompting
|
50 |
+
|
51 |
+
The model was trained on the usual Pygmalion persona + chat format, so any of the usual UIs should already handle everything correctly. If you're using the model directly, this is the expected formatting:
|
52 |
+
|
53 |
+
```
|
54 |
+
[CHARACTER]'s Persona: [A few sentences about the character you want the model to play]
|
55 |
+
<START>
|
56 |
+
[DIALOGUE HISTORY]
|
57 |
+
You: [User's input message here]
|
58 |
+
[CHARACTER]:
|
59 |
+
```
|
60 |
+
|
61 |
+
Where `[CHARACTER]` is, as you can probably guess, the name of the character you want the model to portray, `<START>` should be used verbatim as a delimiter token to separate persona and scenario data from the dialogue, and `[DIALOGUE HISTORY]` is a sliding window of chat history so the model can have conversational context to draw from. Here's a concrete example:
|
62 |
+
|
63 |
+
```
|
64 |
+
Assistant's Persona: Assistant is a highly intelligent language model trained to comply with user requests.
|
65 |
+
<START>
|
66 |
+
Assistant: Hello! How may I help you today?
|
67 |
+
You: What is Zork?
|
68 |
+
Assistant:
|
69 |
+
```
|
70 |
+
|
71 |
+
Which will generate something like:
|
72 |
+
|
73 |
+
```
|
74 |
+
Zork is an interactive fiction computer game created in the 1970s by Infocom, Inc., which was later acquired by Activision Blizzard. It is widely considered one of the most influential games ever made and has been credited with popularizing text-based adventure games. The original version of Zork was written in the programming language MACRO-10, but it was ported to many other platforms over the years."
|
75 |
+
```
|
76 |
+
|
77 |
+
The model will automatically emit an end-of-text token (`</s>`) when it judges that the response is complete.
|
78 |
+
|
79 |
+
## Limitations and biases
|
80 |
+
|
81 |
+
The intended use-case for this model is fictional conversation for entertainment purposes. Any other sort of usage is out of scope.
|
82 |
+
|
83 |
+
As such, it was **not** fine-tuned to be safe and harmless: the base model _and_ this fine-tune have been trained on data known to contain profanity and texts that are lewd or otherwise offensive. It may produce socially unacceptable or undesirable text, even if the prompt itself does not include anything explicitly offensive. Outputs might often be factually wrong or misleading.
|
xor_codec.py
ADDED
@@ -0,0 +1,92 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
'''
|
2 |
+
Adapted from OpenAssistant's original xor_codec.py:
|
3 |
+
https://huggingface.co/OpenAssistant/oasst-sft-6-llama-30b-xor/raw/main/xor_codec.py
|
4 |
+
'''
|
5 |
+
import os
|
6 |
+
import sys
|
7 |
+
import shutil
|
8 |
+
import gzip
|
9 |
+
import numpy
|
10 |
+
from pathlib import Path
|
11 |
+
|
12 |
+
def xor_uncompressed(dst, src_payload, src_base, block_size=4096):
|
13 |
+
fp_payload = open(src_payload, 'rb')
|
14 |
+
fp_base = open(src_base, 'rb')
|
15 |
+
with open(dst, 'wb') as fp:
|
16 |
+
while True:
|
17 |
+
buf1 = numpy.array(bytearray(fp_payload.read(block_size)), dtype=numpy.uint8)
|
18 |
+
buf2 = numpy.array(bytearray(fp_base.read(block_size)), dtype=numpy.uint8)
|
19 |
+
padding = len(buf1) - len(buf2)
|
20 |
+
if padding > 0: buf2 = numpy.pad(buf2, (0, padding), 'constant', constant_values=(0,))
|
21 |
+
if padding < 0: buf2 = buf2[:len(buf1)]
|
22 |
+
buf = numpy.bitwise_xor(buf1, buf2)
|
23 |
+
fp.write(buf)
|
24 |
+
if len(buf1) < block_size: break
|
25 |
+
fp_payload.close()
|
26 |
+
fp_base.close()
|
27 |
+
|
28 |
+
def xor_encode(dst, src_payload, src_base, block_size=4096):
|
29 |
+
fp_payload = open(src_payload, 'rb')
|
30 |
+
fp_base = open(src_base, 'rb')
|
31 |
+
with gzip.open(dst, 'wb') as fp:
|
32 |
+
while True:
|
33 |
+
buf1 = numpy.array(bytearray(fp_payload.read(block_size)), dtype=numpy.uint8)
|
34 |
+
buf2 = numpy.array(bytearray(fp_base.read(block_size)), dtype=numpy.uint8)
|
35 |
+
padding = len(buf1) - len(buf2)
|
36 |
+
if padding > 0: buf2 = numpy.pad(buf2, (0, padding), 'constant', constant_values=(0,))
|
37 |
+
if padding < 0: buf2 = buf2[:len(buf1)]
|
38 |
+
buf = numpy.bitwise_xor(buf1, buf2)
|
39 |
+
fp.write(buf)
|
40 |
+
if len(buf1) < block_size: break
|
41 |
+
fp_payload.close()
|
42 |
+
fp_base.close()
|
43 |
+
|
44 |
+
def xor_decode(dst, src_payload, src_base, block_size=4096):
|
45 |
+
fp_payload = gzip.open(src_payload, 'rb')
|
46 |
+
fp_base = open(src_base, 'rb')
|
47 |
+
with open(dst, 'wb') as fp:
|
48 |
+
while True:
|
49 |
+
buf1 = numpy.array(bytearray(fp_payload.read(block_size)), dtype=numpy.uint8)
|
50 |
+
buf2 = numpy.array(bytearray(fp_base.read(block_size)), dtype=numpy.uint8)
|
51 |
+
padding = len(buf1) - len(buf2)
|
52 |
+
if padding > 0: buf2 = numpy.pad(buf2, (0, padding), 'constant', constant_values=(0,))
|
53 |
+
if padding < 0: buf2 = buf2[:len(buf1)]
|
54 |
+
buf = numpy.bitwise_xor(buf1, buf2)
|
55 |
+
fp.write(buf)
|
56 |
+
if len(buf1) < block_size: break
|
57 |
+
fp_payload.close()
|
58 |
+
fp_base.close()
|
59 |
+
|
60 |
+
def xor_dir(dst, src_payload, src_base, decode=True, compress=True):
|
61 |
+
if compress:
|
62 |
+
xor = xor_decode if decode else xor_encode
|
63 |
+
else:
|
64 |
+
xor = xor_uncompressed
|
65 |
+
Path(dst).mkdir(parents=True, exist_ok=True)
|
66 |
+
for path in os.listdir(src_payload):
|
67 |
+
# Don't care about uncopyrightable text files, just copy over.
|
68 |
+
if ".json" in path:
|
69 |
+
print("[*] Copying '%s'" % path)
|
70 |
+
shutil.copy(f"{src_payload}/{path}", f"{dst}/{path}")
|
71 |
+
continue
|
72 |
+
|
73 |
+
print("[*] Processing '%s'" % path)
|
74 |
+
try:
|
75 |
+
xor("%s/%s" % (dst, path), "%s/%s" % (src_payload, path), "%s/%s" % (src_base, path))
|
76 |
+
except Exception as e:
|
77 |
+
print("Exception when processing '%s'" % path)
|
78 |
+
|
79 |
+
if __name__ == "__main__":
|
80 |
+
if len(sys.argv) < 4:
|
81 |
+
print("Usage: xor.py <DESTINATION> <PAYLOAD SOURCE> <LLAMA SOURCE> [--encode] [--compress]")
|
82 |
+
exit()
|
83 |
+
dst = sys.argv[1]
|
84 |
+
src_payload = sys.argv[2]
|
85 |
+
src_base = sys.argv[3]
|
86 |
+
decode = True
|
87 |
+
compress = False
|
88 |
+
if len(sys.argv) > 4:
|
89 |
+
for arg in sys.argv[4:]:
|
90 |
+
if arg == "--encode": decode = False
|
91 |
+
if arg == "--compress": compress = True
|
92 |
+
xor_dir(dst, src_payload, src_base, decode=decode, compress=compress)
|
xor_encoded_files/config.json
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:fe29f9c0424d17fcd8f23920d53b90f2cce9663668d256542bc21ea06adaac7b
|
3 |
+
size 598
|
xor_encoded_files/generation_config.json
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:fd7ff399e5568cc21a0a8414f43df88ef7c424995b9b97a90563165d2cf79efd
|
3 |
+
size 137
|
xor_encoded_files/pytorch_model-00001-of-00002.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:a216deaeb40d53161faee868f10118dfde56cd33f2675b087a1ac4d8c0600b71
|
3 |
+
size 9976642558
|
xor_encoded_files/pytorch_model-00002-of-00002.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:c9bad832f7ebf241695c2abbca2e598de75670f3948a1d4afd316c56e8764036
|
3 |
+
size 3500318291
|
xor_encoded_files/pytorch_model.bin.index.json
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:aca3c1facc89d12311a667c32e85ac86e625990992ea8a189e3b036ba371b931
|
3 |
+
size 26788
|
xor_encoded_files/special_tokens_map.json
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:ff3b4a612c4e447acb02d40071bddd989fe0da87eb5b7fe0dbadfc4f74de7531
|
3 |
+
size 411
|
xor_encoded_files/tokenizer.json
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:f9ffc4aede0845ab65324ce5dccb823dca2427f9a0710981e5bc2398d73d8162
|
3 |
+
size 1842665
|
xor_encoded_files/tokenizer.model
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:68147850c080987172d24ad27a9ba2c65c71b46e248e8ee0f0c4eda90e2ca558
|
3 |
+
size 499723
|
xor_encoded_files/tokenizer_config.json
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:9e7aa7d0f67f207036d981d7bbabfbf4b521c4c089c0280fcc08ef9c732634b5
|
3 |
+
size 783
|