ff670 commited on
Commit
fdad0f3
·
1 Parent(s): aaac314

Upload decrypt.py

Browse files
Files changed (1) hide show
  1. decrypt.py +48 -0
decrypt.py ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Due to licensing restrictions from LLAMA, you need to have the original LLAMA-7B model to use this model.
2
+ # To decrypt the model weights, obtain the original LLAMA-7B model (not the huggingface version) and run the following command:
3
+ # decrypt.py [path-to-consolidated.00.pth] [path-to-our-model-folder]
4
+
5
+ import os
6
+ import sys
7
+ import glob
8
+ import numpy as np
9
+
10
+ def xor_files(seed_path, input_path, output_path, buffer_size=16*1024*1024):
11
+ # Check if output file exists
12
+ if os.path.exists(output_path):
13
+ print('Skipping already decrypted file: ' + output_path)
14
+ return
15
+ print('Decrypting: ', input_path, ' to ', output_path)
16
+ with open(seed_path, "rb") as seed_file:
17
+ # Read first 16MB of seed file
18
+ seed_data = seed_file.read(buffer_size)
19
+ # store to bufSeed
20
+ bufSeed = np.frombuffer(seed_data, dtype=np.uint8)
21
+
22
+ with open(input_path, "rb") as input_file, open(output_path, "wb") as output_file:
23
+ while True:
24
+ input_data = input_file.read(buffer_size)
25
+ if not input_data:
26
+ break
27
+ inputLen = len(input_data)
28
+ bufTmp = np.frombuffer(input_data, dtype=np.uint8) ^ bufSeed[:inputLen]
29
+ output_data = bufTmp.tobytes()
30
+ output_file.write(output_data)
31
+
32
+
33
+ def main(seed_path, folder_path):
34
+ enc_files = glob.glob(os.path.join(folder_path, "*.enc"))
35
+
36
+ for enc_file in enc_files:
37
+ output_file = os.path.splitext(enc_file)[0]
38
+ xor_files(seed_path, enc_file, output_file)
39
+
40
+ if __name__ == "__main__":
41
+ if len(sys.argv) != 3:
42
+ print("Usage: python decrypt.py <path-to-llama-7b-consolidated.00.pth-file> <our-model-folder>")
43
+ sys.exit(1)
44
+
45
+ seed_path = sys.argv[1]
46
+ folder_path = sys.argv[2]
47
+
48
+ main(seed_path, folder_path)