11b commited on
Commit
bc28ab3
0 Parent(s):

initial release

Browse files
.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,86 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 13B</h1>
12
+ <h2 style="text-align: center">A conversational LLaMA fine-tune.</h2>
13
+
14
+ ## Model Details
15
+
16
+ Pygmalion 13B is a dialogue model based on Meta's LLaMA-13B.
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-13B 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-13b \
31
+ ./xor_encoded_files \
32
+ /path/to/hf-converted/llama-13b \
33
+ --decode
34
+ ```
35
+
36
+ For reference, these are the hashes you should get after following the steps above:
37
+
38
+ ```bash
39
+ $ rhash --sha256 *
40
+ 3b12e6740652990ac386b6136119aaca698aa547d9460e1ef243a7d17d489fe3 config.json
41
+ e14c4af01ea4febe3448d9db29c6dbd982966c5161a31c5185b8fe6d6796509a generation_config.json
42
+ 6b05c8e8ae9c1065e4c7cfd2b61311191d2ad5735a2e4beab98fc53b49375af8 pytorch_model-00001-of-00003.bin
43
+ 4cd096ac310b6bbc3acd3d729277427ad3c3d5740619462dc8f907dfeac3e66f pytorch_model-00002-of-00003.bin
44
+ a2fe9ac5d7005e65c58b8d14818678dd0730689f518612b90cca19fed7c483ad pytorch_model-00003-of-00003.bin
45
+ 72e91e29282dae48ea5562fcf4d6ca0d5a9c2a30ebc8d67174a19e192552a20b pytorch_model.bin.index.json
46
+ ff3b4a612c4e447acb02d40071bddd989fe0da87eb5b7fe0dbadfc4f74de7531 special_tokens_map.json
47
+ f9ffc4aede0845ab65324ce5dccb823dca2427f9a0710981e5bc2398d73d8162 tokenizer.json
48
+ 9e556afd44213b6bd1be2b850ebbbd98f5481437a8021afaf58ee7fb1818d347 tokenizer.model
49
+ 380608719f3af6ef2b343e2ed53bf55556678609337e88a14f58cc49177b9e18 tokenizer_config.json
50
+ ```
51
+
52
+ ## Prompting
53
+
54
+ 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:
55
+
56
+ ```
57
+ [CHARACTER]'s Persona: [A few sentences about the character you want the model to play]
58
+ <START>
59
+ [DIALOGUE HISTORY]
60
+ You: [User's input message here]
61
+ [CHARACTER]:
62
+ ```
63
+
64
+ 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:
65
+
66
+ ```
67
+ Assistant's Persona: Assistant is a highly intelligent language model trained to comply with user requests.
68
+ <START>
69
+ Assistant: Hello! How may I help you today?
70
+ You: What is Zork?
71
+ Assistant:
72
+ ```
73
+
74
+ Which will generate something like:
75
+
76
+ ```
77
+ 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."
78
+ ```
79
+
80
+ The model will automatically emit an end-of-text token (`</s>`) when it judges that the response is complete.
81
+
82
+ ## Limitations and biases
83
+
84
+ The intended use-case for this model is fictional conversation for entertainment purposes. Any other sort of usage is out of scope.
85
+
86
+ 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:3b12e6740652990ac386b6136119aaca698aa547d9460e1ef243a7d17d489fe3
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:e14c4af01ea4febe3448d9db29c6dbd982966c5161a31c5185b8fe6d6796509a
3
+ size 137
xor_encoded_files/pytorch_model-00001-of-00003.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ed8d9d8d0f59e0d6205b1c5d6bc9b85b3358367be059eef840bc26328ca58179
3
+ size 9948728622
xor_encoded_files/pytorch_model-00002-of-00003.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:551373b2bd6162a37eae8d03d7e626aa7c64a0fc70a62794ef047b266298c89e
3
+ size 9904165088
xor_encoded_files/pytorch_model-00003-of-00003.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:fdb2cc42fd5321fe993699f198c8b4fdf7b8f4e4ee1903f6428b4e073f0a0d82
3
+ size 6178983817
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:72e91e29282dae48ea5562fcf4d6ca0d5a9c2a30ebc8d67174a19e192552a20b
3
+ size 33444
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:380608719f3af6ef2b343e2ed53bf55556678609337e88a14f58cc49177b9e18
3
+ size 700