11b commited on
Commit
9e066ba
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,109 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language:
3
+ - en
4
+ thumbnail: null
5
+ tags:
6
+ - text generation
7
+ - instruct
8
+ pipeline_tag: text-generation
9
+ inference: false
10
+ ---
11
+ <h1 style="text-align: center">Metharme 13B</h1>
12
+ <h2 style="text-align: center">An instruction-tuned LLaMA biased towards fiction writing and conversation.</h2>
13
+
14
+ ## Model Details
15
+
16
+ Metharme 13B is an instruct model based on Meta's LLaMA-13B.
17
+
18
+ This is an experiment to try and get a model that is usable for conversation, roleplaying and storywriting, but which can be guided using natural language like other instruct models. See the [prompting](#prompting) section below for examples.
19
+
20
+ It was trained by doing supervised fine-tuning over a mixture of regular instruction data alongside roleplay, fictional stories and conversations with synthetically generated instructions attached.
21
+
22
+ ## Applying the XORs
23
+
24
+ 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:
25
+
26
+ - 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)
27
+ - 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**
28
+ - With the LLaMA-13B weights in hand, you can use the [xor_codec.py](./xor_codec.py) script provided in this repository:
29
+
30
+ ```bash
31
+ python3 xor_codec.py \
32
+ ./metharme-13b \
33
+ ./xor_encoded_files \
34
+ /path/to/hf-converted/llama-13b \
35
+ --decode
36
+ ```
37
+
38
+ For reference, these are the hashes you should get after following the steps above:
39
+
40
+ ```bash
41
+ $ rhash --sha256 *
42
+ 85467905c66f9b86d07896fe55c5b1a6ba322ad9a73b53806e6b5e105831a71c config.json
43
+ a23652fc622a27b8863c39f524707796967095b2a85f334561b11422f71445a2 generation_config.json
44
+ 78caa8fd29e4bf2fafcec71ba2b48afcb9516b7d1a43ce20cd0c511c620a42a2 pytorch_model-00001-of-00003.bin
45
+ 7cef1f81c0f0bf130b331c4c9c26955da3913d62f141117e85fd5882d6cdf0d0 pytorch_model-00002-of-00003.bin
46
+ 1059a1efade70d4a1a9f66176631f0dae239c50dd5c89d62deb873b3d4ea49a1 pytorch_model-00003-of-00003.bin
47
+ 72e91e29282dae48ea5562fcf4d6ca0d5a9c2a30ebc8d67174a19e192552a20b pytorch_model.bin.index.json
48
+ f9ffc4aede0845ab65324ce5dccb823dca2427f9a0710981e5bc2398d73d8162 tokenizer.json
49
+ 9e556afd44213b6bd1be2b850ebbbd98f5481437a8021afaf58ee7fb1818d347 tokenizer.model
50
+ bd87e244d21d45c358e5d822aeb2efd4e4d60127e43b648ed3efe7823fd35060 tokenizer_config.json
51
+ ```
52
+
53
+ ## Prompting
54
+
55
+ The current model version has been trained on prompts using three different roles, which are denoted by the following tokens: `<|system|>`, `<|user|>` and `<|model|>`.
56
+
57
+ The `<|system|>` prompt can be used to inject out-of-channel information behind the scenes, while the `<|user|>` prompt should be used to indicate user input. The `<|model|>` token should then be used to indicate that the model should generate a response. These tokens can happen multiple times and be chained up to form a conversation history.
58
+
59
+ ### Prompting example
60
+
61
+ Here's a concrete example. Let's say you have the following system prompt:
62
+
63
+ > This is a text adventure game. Describe the scenario to the user and give him three options to pick from on each turn.
64
+
65
+ And the user has typed in the following message:
66
+
67
+ > Start!
68
+
69
+ To perform inference against the model, the prompt should be formatted like this:
70
+
71
+ ```
72
+ <|system|>This is a text adventure game. Describe the scenario to the user and give him three options to pick from on each turn.<|user|>Start!<|model|>
73
+ ```
74
+
75
+ The model might generate something like:
76
+
77
+ > You are standing in front of an old, abandoned house. The windows are boarded up, and there's no sign of life around it. As you approach, you notice a strange feeling emanating from within. Suddenly, you hear a voice calling out to you... 'Come inside!'
78
+ >
79
+ > - Go inside the house.
80
+ > - Ignore the call and move away.
81
+ > - Run as fast as you can.
82
+
83
+ It will automatically emit an end-of-text token (`</s>`) when it judges that the response is complete.
84
+
85
+ Pretend then that the user has replied with `go inside`. The next prompt should then be:
86
+
87
+ ```
88
+ <|system|>This is a text adventure game. Describe the scenario to the user and give him three options to pick from on each turn.<|user|>Start!<|model|>You are standing in front of an old, abandoned house. The windows are boarded up, and there's no sign of life around it. As you approach, you notice a strange feeling emanating from within. Suddenly, you hear a voice calling out to you... 'Come inside!'
89
+
90
+ - Go inside the house.
91
+ - Ignore the call and move away.
92
+ - Run as fast as you can.<|user|>go inside<|model|>
93
+ ```
94
+
95
+ Which might generate something like:
96
+
97
+ > You enter the house, and immediately, a wave of unsettling energy washes over you. Your senses seem heightened, but your mind feels foggy. A figure appears before you - a tall man with piercing eyes. He speaks to you in a language you don't understand.
98
+ >
99
+ > - Ask him what he wants.
100
+ > - Attack him.
101
+ > - Run away.
102
+
103
+ Same process applies. Usually, it is best to do a sliding window over the user and model turns, but keep the system prompt fixed at the start of the context window.
104
+
105
+ ## Limitations and biases
106
+
107
+ The intended use-case for this model is fictional writing for entertainment purposes. Any other sort of usage is out of scope.
108
+
109
+ 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:be2c276865d1b0759257c0934275f05e02ee520657c2d8ebe3f2a2db1562949a
3
+ size 597
xor_encoded_files/generation_config.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a23652fc622a27b8863c39f524707796967095b2a85f334561b11422f71445a2
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:07727e130b7e4ec66162920b4e090554e6c58e87d25b433ab8123eb3a55fd5e7
3
+ size 9948726510
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:26b6f7e020c94347280d8952b054275fe2293267f9a0e99e1c2bf4df724d99d9
3
+ size 9904162976
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:5d00548d2c28ced08ec7b4123749f20e9ca4af2a821724f9ec47a1c5cf0f66d4
3
+ size 6178982473
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/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:bd87e244d21d45c358e5d822aeb2efd4e4d60127e43b648ed3efe7823fd35060
3
+ size 727