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

release v1

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,85 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ **Note for Windows users:** If you're on Windows, you might run into issues where following the steps above will result in corrupted files. This seems to be because `git` messes with the encoding of text files (so the `.json`s and other relevant files). To avoid this, use WSL. For reference, these are the MD5 hashes you should get after following the steps above:
37
+
38
+ ```bash
39
+ $ rhash -M *
40
+ 4608facb4910118f8dfa80f090cbc4dc config.json
41
+ 2917a1cafb895cf57e746cfd7696bfe5 generation_config.json
42
+ 98764eb949eea16f8e2e1c2d3dea0066 pytorch_model-00001-of-00002.bin
43
+ be9ba2f37228a0a9ea0eaf6530aba4de pytorch_model-00002-of-00002.bin
44
+ 81648ef3915ed2e83d49fed93122d53e pytorch_model.bin.index.json
45
+ 6b2e0a735969660e720c27061ef3f3d3 special_tokens_map.json
46
+ fdb311c39b8659a5d5c1991339bafc09 tokenizer.json
47
+ eeec4125e9c7560836b4873b6f8e3025 tokenizer.model
48
+ f0b65b44265ba51881b1e1881102504f tokenizer_config.json
49
+ ```
50
+
51
+ ## Prompting
52
+
53
+ 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:
54
+
55
+ ```
56
+ [CHARACTER]'s Persona: [A few sentences about the character you want the model to play]
57
+ <START>
58
+ [DIALOGUE HISTORY]
59
+ You: [User's input message here]
60
+ [CHARACTER]:
61
+ ```
62
+
63
+ 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:
64
+
65
+ ```
66
+ Assistant's Persona: Assistant is a highly intelligent language model trained to comply with user requests.
67
+ <START>
68
+ Assistant: Hello! How may I help you today?
69
+ You: What is Zork?
70
+ Assistant:
71
+ ```
72
+
73
+ Which will generate something like:
74
+
75
+ ```
76
+ 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."
77
+ ```
78
+
79
+ The model will automatically emit an end-of-text token (`</s>`) when it judges that the response is complete.
80
+
81
+ ## Limitations and biases
82
+
83
+ The intended use-case for this model is fictional conversation for entertainment purposes. Any other sort of usage is out of scope.
84
+
85
+ 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,85 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 gzip
8
+ import numpy
9
+ from pathlib import Path
10
+
11
+ def xor_uncompressed(dst, src_payload, src_base, block_size=4096):
12
+ fp_payload = open(src_payload, 'rb')
13
+ fp_base = open(src_base, 'rb')
14
+ with open(dst, 'wb') as fp:
15
+ while True:
16
+ buf1 = numpy.array(bytearray(fp_payload.read(block_size)), dtype=numpy.uint8)
17
+ buf2 = numpy.array(bytearray(fp_base.read(block_size)), dtype=numpy.uint8)
18
+ padding = len(buf1) - len(buf2)
19
+ if padding > 0: buf2 = numpy.pad(buf2, (0, padding), 'constant', constant_values=(0,))
20
+ if padding < 0: buf2 = buf2[:len(buf1)]
21
+ buf = numpy.bitwise_xor(buf1, buf2)
22
+ fp.write(buf)
23
+ if len(buf1) < block_size: break
24
+ fp_payload.close()
25
+ fp_base.close()
26
+
27
+ def xor_encode(dst, src_payload, src_base, block_size=4096):
28
+ fp_payload = open(src_payload, 'rb')
29
+ fp_base = open(src_base, 'rb')
30
+ with gzip.open(dst, 'wb') as fp:
31
+ while True:
32
+ buf1 = numpy.array(bytearray(fp_payload.read(block_size)), dtype=numpy.uint8)
33
+ buf2 = numpy.array(bytearray(fp_base.read(block_size)), dtype=numpy.uint8)
34
+ padding = len(buf1) - len(buf2)
35
+ if padding > 0: buf2 = numpy.pad(buf2, (0, padding), 'constant', constant_values=(0,))
36
+ if padding < 0: buf2 = buf2[:len(buf1)]
37
+ buf = numpy.bitwise_xor(buf1, buf2)
38
+ fp.write(buf)
39
+ if len(buf1) < block_size: break
40
+ fp_payload.close()
41
+ fp_base.close()
42
+
43
+ def xor_decode(dst, src_payload, src_base, block_size=4096):
44
+ fp_payload = gzip.open(src_payload, 'rb')
45
+ fp_base = open(src_base, 'rb')
46
+ with open(dst, 'wb') as fp:
47
+ while True:
48
+ buf1 = numpy.array(bytearray(fp_payload.read(block_size)), dtype=numpy.uint8)
49
+ buf2 = numpy.array(bytearray(fp_base.read(block_size)), dtype=numpy.uint8)
50
+ padding = len(buf1) - len(buf2)
51
+ if padding > 0: buf2 = numpy.pad(buf2, (0, padding), 'constant', constant_values=(0,))
52
+ if padding < 0: buf2 = buf2[:len(buf1)]
53
+ buf = numpy.bitwise_xor(buf1, buf2)
54
+ fp.write(buf)
55
+ if len(buf1) < block_size: break
56
+ fp_payload.close()
57
+ fp_base.close()
58
+
59
+ def xor_dir(dst, src_payload, src_base, decode=True, compress=True):
60
+ if compress:
61
+ xor = xor_decode if decode else xor_encode
62
+ else:
63
+ xor = xor_uncompressed
64
+ Path(dst).mkdir(parents=True, exist_ok=True)
65
+ for path in os.listdir(src_payload):
66
+ print("[*] Processing '%s'" % path)
67
+ try:
68
+ xor("%s/%s" % (dst, path), "%s/%s" % (src_payload, path), "%s/%s" % (src_base, path))
69
+ except Exception as e:
70
+ print("Exception when processing '%s'" % path)
71
+
72
+ if __name__ == "__main__":
73
+ if len(sys.argv) < 4:
74
+ print("Usage: xor.py <DESTINATION> <PAYLOAD SOURCE> <LLAMA SOURCE> [--encode] [--compress]")
75
+ exit()
76
+ dst = sys.argv[1]
77
+ src_payload = sys.argv[2]
78
+ src_base = sys.argv[3]
79
+ decode = True
80
+ compress = False
81
+ if len(sys.argv) > 4:
82
+ for arg in sys.argv[4:]:
83
+ if arg == "--encode": decode = False
84
+ if arg == "--compress": compress = True
85
+ 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:89f8649bb9ba162ad7f95167028f4230a2b9a597d5c9e6e28a2a6e45e2b8fb70
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:4a93894f08d98d707cd9a0274f4c9a51bcfa27e701359e12befcc78ffb488817
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:4be5669c4eb805f9afb7648438733b6ff1a3fa0d988b4165cf353929c2b89d4f
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:5f7bcd85900e62abb00ce739eaad53d80170a4a6152d951b6825110d2fc17965
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:721b8a5e36fc955713c7b5705281b2144e3505ee46a6194ebb39299d941094a9
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:8cf2eeac1040c1965ce9f8333c2e763b4aba5366d3b3f3367807741325304dfb
3
+ size 831