Compress with ZipNN
Browse files- .gitattributes +1 -0
- README.md +25 -9
- __pycache__/zipnn_compress_file.cpython-310.pyc +0 -0
- model-00001-of-00021.safetensors → model-00001-of-00021.safetensors.znn +2 -2
- model-00002-of-00021.safetensors → model-00002-of-00021.safetensors.znn +2 -2
- model-00003-of-00021.safetensors → model-00003-of-00021.safetensors.znn +2 -2
- model-00004-of-00021.safetensors → model-00004-of-00021.safetensors.znn +2 -2
- model-00005-of-00021.safetensors +0 -3
- model-00005-of-00021.safetensors.znn +3 -0
- model-00006-of-00021.safetensors +0 -3
- model-00006-of-00021.safetensors.znn +3 -0
- model-00007-of-00021.safetensors +0 -3
- model-00007-of-00021.safetensors.znn +3 -0
- model-00008-of-00021.safetensors +0 -3
- model-00008-of-00021.safetensors.znn +3 -0
- model-00009-of-00021.safetensors +0 -3
- model-00009-of-00021.safetensors.znn +3 -0
- model-00010-of-00021.safetensors +0 -3
- model-00010-of-00021.safetensors.znn +3 -0
- model-00011-of-00021.safetensors +0 -3
- model-00011-of-00021.safetensors.znn +3 -0
- model-00012-of-00021.safetensors +0 -3
- model-00012-of-00021.safetensors.znn +3 -0
- model-00013-of-00021.safetensors +0 -3
- model-00013-of-00021.safetensors.znn +3 -0
- model-00014-of-00021.safetensors +0 -3
- model-00014-of-00021.safetensors.znn +3 -0
- model-00015-of-00021.safetensors +0 -3
- model-00015-of-00021.safetensors.znn +3 -0
- model-00016-of-00021.safetensors +0 -3
- model-00016-of-00021.safetensors.znn +3 -0
- model-00017-of-00021.safetensors +0 -3
- model-00017-of-00021.safetensors.znn +3 -0
- model-00018-of-00021.safetensors +0 -3
- model-00018-of-00021.safetensors.znn +3 -0
- model-00019-of-00021.safetensors +0 -3
- model-00019-of-00021.safetensors.znn +3 -0
- model-00020-of-00021.safetensors +0 -3
- model-00020-of-00021.safetensors.znn +3 -0
- model-00021-of-00021.safetensors +0 -3
- model-00021-of-00021.safetensors.znn +3 -0
- zipnn_compress_file.py +154 -0
- zipnn_compress_path.py +253 -0
- zipnn_decompress_file.py +84 -0
- zipnn_decompress_path.py +184 -0
.gitattributes
CHANGED
|
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
*.znn filter=lfs diff=lfs merge=lfs -text
|
README.md
CHANGED
|
@@ -5,6 +5,7 @@ tags:
|
|
| 5 |
- jamba
|
| 6 |
- mamba
|
| 7 |
- moe
|
|
|
|
| 8 |
---
|
| 9 |
|
| 10 |
# Model Card for Jamba
|
|
@@ -15,6 +16,8 @@ Jamba is the first production-scale Mamba implementation, which opens up interes
|
|
| 15 |
|
| 16 |
This model card is for the base version of Jamba. It’s a pretrained, mixture-of-experts (MoE) generative text model, with 12B active parameters and a total of 52B parameters across all experts. It supports a 256K context length, and can fit up to 140K tokens on a single 80GB GPU.
|
| 17 |
|
|
|
|
|
|
|
| 18 |
For full details of this model please read the [white paper](https://arxiv.org/abs/2403.19887) and the [release blog post](https://www.ai21.com/blog/announcing-jamba).
|
| 19 |
|
| 20 |
## Model Details
|
|
@@ -40,12 +43,25 @@ You also have to have the model on a CUDA device.
|
|
| 40 |
|
| 41 |
You can run the model not using the optimized Mamba kernels, but it is **not** recommended as it will result in significantly lower latencies. In order to do that, you'll need to specify `use_mamba_kernels=False` when loading the model.
|
| 42 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
### Run the model
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
```python
|
| 45 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 46 |
|
| 47 |
-
model = AutoModelForCausalLM.from_pretrained("
|
| 48 |
-
tokenizer = AutoTokenizer.from_pretrained("
|
| 49 |
|
| 50 |
input_ids = tokenizer("In the recent Super Bowl LVIII,", return_tensors='pt').to(model.device)["input_ids"]
|
| 51 |
|
|
@@ -65,7 +81,7 @@ Please note that if you're using `transformers<4.40.0`, `trust_remote_code=True`
|
|
| 65 |
```python
|
| 66 |
from transformers import AutoModelForCausalLM
|
| 67 |
import torch
|
| 68 |
-
model = AutoModelForCausalLM.from_pretrained("
|
| 69 |
torch_dtype=torch.bfloat16) # you can also use torch_dtype=torch.float16
|
| 70 |
```
|
| 71 |
|
|
@@ -73,7 +89,7 @@ When using half precision, you can enable the [FlashAttention2](https://github.c
|
|
| 73 |
```python
|
| 74 |
from transformers import AutoModelForCausalLM
|
| 75 |
import torch
|
| 76 |
-
model = AutoModelForCausalLM.from_pretrained("
|
| 77 |
torch_dtype=torch.bfloat16,
|
| 78 |
attn_implementation="flash_attention_2",
|
| 79 |
device_map="auto")
|
|
@@ -88,7 +104,7 @@ model = AutoModelForCausalLM.from_pretrained("ai21labs/Jamba-v0.1",
|
|
| 88 |
from transformers import AutoModelForCausalLM, BitsAndBytesConfig
|
| 89 |
quantization_config = BitsAndBytesConfig(load_in_8bit=True,
|
| 90 |
llm_int8_skip_modules=["mamba"])
|
| 91 |
-
model = AutoModelForCausalLM.from_pretrained("
|
| 92 |
torch_dtype=torch.bfloat16,
|
| 93 |
attn_implementation="flash_attention_2",
|
| 94 |
quantization_config=quantization_config)
|
|
@@ -105,9 +121,9 @@ from trl import SFTTrainer, SFTConfig
|
|
| 105 |
from peft import LoraConfig
|
| 106 |
from transformers import AutoTokenizer, AutoModelForCausalLM, TrainingArguments
|
| 107 |
|
| 108 |
-
tokenizer = AutoTokenizer.from_pretrained("
|
| 109 |
-
model = AutoModelForCausalLM.from_pretrained(
|
| 110 |
-
|
| 111 |
|
| 112 |
lora_config = LoraConfig(
|
| 113 |
r=8,
|
|
@@ -164,4 +180,4 @@ As a base model, Jamba is intended for use as a foundation layer for fine tuning
|
|
| 164 |
## About AI21
|
| 165 |
AI21 builds reliable, practical, and scalable AI solutions for the enterprise.
|
| 166 |
|
| 167 |
-
Jamba is the first in AI21’s new family of models, and the Instruct version of Jamba is coming soon to the [AI21 platform](https://www.ai21.com/studio).
|
|
|
|
| 5 |
- jamba
|
| 6 |
- mamba
|
| 7 |
- moe
|
| 8 |
+
base_model: ai21labs/Jamba-v0.1
|
| 9 |
---
|
| 10 |
|
| 11 |
# Model Card for Jamba
|
|
|
|
| 16 |
|
| 17 |
This model card is for the base version of Jamba. It’s a pretrained, mixture-of-experts (MoE) generative text model, with 12B active parameters and a total of 52B parameters across all experts. It supports a 256K context length, and can fit up to 140K tokens on a single 80GB GPU.
|
| 18 |
|
| 19 |
+
This fork is compressed using **ZipNN**. To use the model, decompress the model tensors as discribed below and load the **local** weights.
|
| 20 |
+
|
| 21 |
For full details of this model please read the [white paper](https://arxiv.org/abs/2403.19887) and the [release blog post](https://www.ai21.com/blog/announcing-jamba).
|
| 22 |
|
| 23 |
## Model Details
|
|
|
|
| 43 |
|
| 44 |
You can run the model not using the optimized Mamba kernels, but it is **not** recommended as it will result in significantly lower latencies. In order to do that, you'll need to specify `use_mamba_kernels=False` when loading the model.
|
| 45 |
|
| 46 |
+
You need to [clone this repository](https://huggingface.co/royleibov/Jamba-v0.1-ZipNN-Compressed?clone=true) to decompress the model.
|
| 47 |
+
|
| 48 |
+
Then:
|
| 49 |
+
```bash
|
| 50 |
+
cd Jamba-v0.1-ZipNN-Compressed
|
| 51 |
+
```
|
| 52 |
+
|
| 53 |
+
|
| 54 |
### Run the model
|
| 55 |
+
First decompress the model weights:
|
| 56 |
+
```bash
|
| 57 |
+
python3 zipnn_decompress_path.py --path .
|
| 58 |
+
```
|
| 59 |
+
|
| 60 |
```python
|
| 61 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 62 |
|
| 63 |
+
model = AutoModelForCausalLM.from_pretrained("PATH_TO_MODEL") # "." if in directory
|
| 64 |
+
tokenizer = AutoTokenizer.from_pretrained("PATH_TO_MODEL") # "." if in directory
|
| 65 |
|
| 66 |
input_ids = tokenizer("In the recent Super Bowl LVIII,", return_tensors='pt').to(model.device)["input_ids"]
|
| 67 |
|
|
|
|
| 81 |
```python
|
| 82 |
from transformers import AutoModelForCausalLM
|
| 83 |
import torch
|
| 84 |
+
model = AutoModelForCausalLM.from_pretrained("PATH_TO_MODEL", # "." if in directory,
|
| 85 |
torch_dtype=torch.bfloat16) # you can also use torch_dtype=torch.float16
|
| 86 |
```
|
| 87 |
|
|
|
|
| 89 |
```python
|
| 90 |
from transformers import AutoModelForCausalLM
|
| 91 |
import torch
|
| 92 |
+
model = AutoModelForCausalLM.from_pretrained("PATH_TO_MODEL", # "." if in directory
|
| 93 |
torch_dtype=torch.bfloat16,
|
| 94 |
attn_implementation="flash_attention_2",
|
| 95 |
device_map="auto")
|
|
|
|
| 104 |
from transformers import AutoModelForCausalLM, BitsAndBytesConfig
|
| 105 |
quantization_config = BitsAndBytesConfig(load_in_8bit=True,
|
| 106 |
llm_int8_skip_modules=["mamba"])
|
| 107 |
+
model = AutoModelForCausalLM.from_pretrained("PATH_TO_MODEL", # "." if in directory
|
| 108 |
torch_dtype=torch.bfloat16,
|
| 109 |
attn_implementation="flash_attention_2",
|
| 110 |
quantization_config=quantization_config)
|
|
|
|
| 121 |
from peft import LoraConfig
|
| 122 |
from transformers import AutoTokenizer, AutoModelForCausalLM, TrainingArguments
|
| 123 |
|
| 124 |
+
tokenizer = AutoTokenizer.from_pretrained("PATH_TO_MODEL") # "." if in directory
|
| 125 |
+
model = AutoModelForCausalLM.from_pretrained("PATH_TO_MODEL", # "." if in directory
|
| 126 |
+
device_map='auto', torch_dtype=torch.bfloat16)
|
| 127 |
|
| 128 |
lora_config = LoraConfig(
|
| 129 |
r=8,
|
|
|
|
| 180 |
## About AI21
|
| 181 |
AI21 builds reliable, practical, and scalable AI solutions for the enterprise.
|
| 182 |
|
| 183 |
+
Jamba is the first in AI21’s new family of models, and the Instruct version of Jamba is coming soon to the [AI21 platform](https://www.ai21.com/studio).
|
__pycache__/zipnn_compress_file.cpython-310.pyc
ADDED
|
Binary file (3.55 kB). View file
|
|
|
model-00001-of-00021.safetensors → model-00001-of-00021.safetensors.znn
RENAMED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:5672600d8bd2ea86bae0221aeebc20529037277e37962ad8e08740ee1feb8511
|
| 3 |
+
size 3284450972
|
model-00002-of-00021.safetensors → model-00002-of-00021.safetensors.znn
RENAMED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:e0dd5e53d72994e77da0a3f1f1a3f10aacdd8b174f9e4cb4da213af8a17765d7
|
| 3 |
+
size 3237752699
|
model-00003-of-00021.safetensors → model-00003-of-00021.safetensors.znn
RENAMED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:e1d36f63b738cce501b21d26e5134ac01264d2f4f92db6e9b13159ac5a8491b4
|
| 3 |
+
size 3310042993
|
model-00004-of-00021.safetensors → model-00004-of-00021.safetensors.znn
RENAMED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:0dcd88e533ae4d28f9e5aad9e72aa11e0f01dbf107838088bf8148d18d85749b
|
| 3 |
+
size 3286974369
|
model-00005-of-00021.safetensors
DELETED
|
@@ -1,3 +0,0 @@
|
|
| 1 |
-
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:c4b0ec6e8f33e6d7b1f837cd4c25818487dcc7e478734606da28110507e51c97
|
| 3 |
-
size 4975763832
|
|
|
|
|
|
|
|
|
|
|
|
model-00005-of-00021.safetensors.znn
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:0ea2482e5fef7f57f17c328470f0351e233e6c9dc06b47edf5ce2e043013621f
|
| 3 |
+
size 3298442475
|
model-00006-of-00021.safetensors
DELETED
|
@@ -1,3 +0,0 @@
|
|
| 1 |
-
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:ed98d5c3c8d7ab7352944bea09b0d54d98066cf567ba3d069da12c05575d56ed
|
| 3 |
-
size 4884669616
|
|
|
|
|
|
|
|
|
|
|
|
model-00006-of-00021.safetensors.znn
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:87f0ce7030dcb77737feefe531c0083664ed5cbc088e08104b95f4d867028abf
|
| 3 |
+
size 3237963769
|
model-00007-of-00021.safetensors
DELETED
|
@@ -1,3 +0,0 @@
|
|
| 1 |
-
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:735be2bc568711bf42a4caebcda8288dd300b31b48fa098b00df3cf1a98e10e2
|
| 3 |
-
size 4884669640
|
|
|
|
|
|
|
|
|
|
|
|
model-00007-of-00021.safetensors.znn
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:50e003b6df8e3656af26a0801b7606a8ecc821fcbf948fe8e51ee5c23a78e480
|
| 3 |
+
size 3237782364
|
model-00008-of-00021.safetensors
DELETED
|
@@ -1,3 +0,0 @@
|
|
| 1 |
-
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:d0c8d817b2b47661d361e8b520128b3194185f756cc2204a95d642e24895ee51
|
| 3 |
-
size 4992557176
|
|
|
|
|
|
|
|
|
|
|
|
model-00008-of-00021.safetensors.znn
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:6b7474f52e0f64f4fb8eff4eb0cfaca77fa0ff9fc326d9f807ab26ac41343b33
|
| 3 |
+
size 3309709335
|
model-00009-of-00021.safetensors
DELETED
|
@@ -1,3 +0,0 @@
|
|
| 1 |
-
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:e50222cf865ca5678d22574b131294303c46b249478cf70113c701f70331e999
|
| 3 |
-
size 4932507176
|
|
|
|
|
|
|
|
|
|
|
|
model-00009-of-00021.safetensors.znn
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:b7473259c0c236438c98ef334d253d08b80535d011e521a81bfb139b2fbaba49
|
| 3 |
+
size 3268999814
|
model-00010-of-00021.safetensors
DELETED
|
@@ -1,3 +0,0 @@
|
|
| 1 |
-
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:b1b4b69b24ae55827b6c8b1e4a10807aa3525bc85f4d34dc002ac7440757fbf4
|
| 3 |
-
size 4884669672
|
|
|
|
|
|
|
|
|
|
|
|
model-00010-of-00021.safetensors.znn
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:5fcb191dd57edb3cb4dd26edef689b47c4585dc9821beeb33f35f4aa222c5a5f
|
| 3 |
+
size 3237672285
|
model-00011-of-00021.safetensors
DELETED
|
@@ -1,3 +0,0 @@
|
|
| 1 |
-
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:60213cac13b92ed34b93ce48e670434f22e3bf8b2b8df20c60b7bf8a9515c35c
|
| 3 |
-
size 4884669696
|
|
|
|
|
|
|
|
|
|
|
|
model-00011-of-00021.safetensors.znn
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:726bb3b6034717691b4c5009400e84bcdd94afb9ba2fe11444b80844621b64bb
|
| 3 |
+
size 3237922482
|
model-00012-of-00021.safetensors
DELETED
|
@@ -1,3 +0,0 @@
|
|
| 1 |
-
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:05805eacd3bb40cc9da802350409f1cb078e8b276da7e06c7a8a5ca5b26cc887
|
| 3 |
-
size 4884669688
|
|
|
|
|
|
|
|
|
|
|
|
model-00012-of-00021.safetensors.znn
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:e309bad973392920171a6bc8ff8504d0be97a91c6ff036da65c584c5b7e56779
|
| 3 |
+
size 3238025909
|
model-00013-of-00021.safetensors
DELETED
|
@@ -1,3 +0,0 @@
|
|
| 1 |
-
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:201df979a1b34ced6cdbb7a790163412636779f1119e3845a704c489181d03d2
|
| 3 |
-
size 4932507176
|
|
|
|
|
|
|
|
|
|
|
|
model-00013-of-00021.safetensors.znn
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:47397c014f6d5d7606818342b17501ff6f8f39083950edc8231c38bcb9d4406d
|
| 3 |
+
size 3269900475
|
model-00014-of-00021.safetensors
DELETED
|
@@ -1,3 +0,0 @@
|
|
| 1 |
-
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:d0a7eb42a9ea3a385442c2e758dd5efd5dc5b913f1d10bfd37792cc963a33c93
|
| 3 |
-
size 4992557152
|
|
|
|
|
|
|
|
|
|
|
|
model-00014-of-00021.safetensors.znn
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:7b92a3a5a36d454f05bce1bee02e4d4fb1aba7524c90ab24d685f6acd4fe4f7f
|
| 3 |
+
size 3309600217
|
model-00015-of-00021.safetensors
DELETED
|
@@ -1,3 +0,0 @@
|
|
| 1 |
-
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:a4b9afe4398000c28b36e3aa40c87086af673d4f8a64bfc5767941ab2008bcc9
|
| 3 |
-
size 4884669688
|
|
|
|
|
|
|
|
|
|
|
|
model-00015-of-00021.safetensors.znn
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:128b215d75d3d083659a1c1be9af377ff9d617abf3aceba112d77f69a1717678
|
| 3 |
+
size 3237503014
|
model-00016-of-00021.safetensors
DELETED
|
@@ -1,3 +0,0 @@
|
|
| 1 |
-
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:dd1ac6cc861971c43bdf0c9c6d4c9fe72d33e5227e054a621e2e68f001419763
|
| 3 |
-
size 4884669688
|
|
|
|
|
|
|
|
|
|
|
|
model-00016-of-00021.safetensors.znn
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:0942f4313f079e387190a07de9ca682ad2815f4060f26a2a8f14eec61abd1f24
|
| 3 |
+
size 3237635876
|
model-00017-of-00021.safetensors
DELETED
|
@@ -1,3 +0,0 @@
|
|
| 1 |
-
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:52d9eea696dd29ef413d617bbcb62a9f159e8fe8170d36e018932cef45ee281d
|
| 3 |
-
size 4908522856
|
|
|
|
|
|
|
|
|
|
|
|
model-00017-of-00021.safetensors.znn
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:2224a44f37673e2f03e88937359d1c26895dc5ebffc20b1ce9ab617b090393c2
|
| 3 |
+
size 3253266376
|
model-00018-of-00021.safetensors
DELETED
|
@@ -1,3 +0,0 @@
|
|
| 1 |
-
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:77acada7c098e81280645ea0a9dbfa00196dca6da8946498b9907e9e376fb42d
|
| 3 |
-
size 4908654000
|
|
|
|
|
|
|
|
|
|
|
|
model-00018-of-00021.safetensors.znn
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:1ded434067927484c6ee52fb6f7e677f3d57a4c7f1ead0f34b11a18968bddaa8
|
| 3 |
+
size 3253812738
|
model-00019-of-00021.safetensors
DELETED
|
@@ -1,3 +0,0 @@
|
|
| 1 |
-
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:09e10dfd6c6459cd3460b1d667639717d3657274c1694c19a6fdbac1be6a76bf
|
| 3 |
-
size 4992557168
|
|
|
|
|
|
|
|
|
|
|
|
model-00019-of-00021.safetensors.znn
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:3382ceb4b2101b8714f0b1a41e06debfdaa947dd8a1ed2257314c837a7b1bbf9
|
| 3 |
+
size 3308468840
|
model-00020-of-00021.safetensors
DELETED
|
@@ -1,3 +0,0 @@
|
|
| 1 |
-
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:2bd5c27b2cca6e06f7b4497ce8c9b1522a64846817a871bad274d08507960ed0
|
| 3 |
-
size 4884669696
|
|
|
|
|
|
|
|
|
|
|
|
model-00020-of-00021.safetensors.znn
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:f7ce533fe923573760a664973927816bbf39efa9c39a7cb10d0539068873869c
|
| 3 |
+
size 3237872986
|
model-00021-of-00021.safetensors
DELETED
|
@@ -1,3 +0,0 @@
|
|
| 1 |
-
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:a47ef23db8deb5364da676a40dc3dcb011fb9d9ceef13ba044c176e9a83ac1e3
|
| 3 |
-
size 4647318576
|
|
|
|
|
|
|
|
|
|
|
|
model-00021-of-00021.safetensors.znn
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:322bce95bcb7f0fabc5fd1f610a4b2aca6eed1bf576104e01aebb17b1337f2a9
|
| 3 |
+
size 3080471330
|
zipnn_compress_file.py
ADDED
|
@@ -0,0 +1,154 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import subprocess
|
| 3 |
+
import sys
|
| 4 |
+
import argparse
|
| 5 |
+
import time
|
| 6 |
+
|
| 7 |
+
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
|
| 8 |
+
|
| 9 |
+
KB = 1024
|
| 10 |
+
MB = 1024 * 1024
|
| 11 |
+
GB = 1024 * 1024 * 1024
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
def check_and_install_zipnn():
|
| 15 |
+
try:
|
| 16 |
+
import zipnn
|
| 17 |
+
except ImportError:
|
| 18 |
+
print("zipnn not found. Installing...")
|
| 19 |
+
subprocess.check_call(
|
| 20 |
+
[
|
| 21 |
+
sys.executable,
|
| 22 |
+
"-m",
|
| 23 |
+
"pip",
|
| 24 |
+
"install",
|
| 25 |
+
"zipnn",
|
| 26 |
+
"--upgrade",
|
| 27 |
+
]
|
| 28 |
+
)
|
| 29 |
+
import zipnn
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
def parse_streaming_chunk_size(
|
| 33 |
+
streaming_chunk_size,
|
| 34 |
+
):
|
| 35 |
+
if str(streaming_chunk_size).isdigit():
|
| 36 |
+
final = int(streaming_chunk_size)
|
| 37 |
+
else:
|
| 38 |
+
size_value = int(streaming_chunk_size[:-2])
|
| 39 |
+
size_unit = streaming_chunk_size[-2].lower()
|
| 40 |
+
|
| 41 |
+
if size_unit == "k":
|
| 42 |
+
final = KB * size_value
|
| 43 |
+
elif size_unit == "m":
|
| 44 |
+
final = MB * size_value
|
| 45 |
+
elif size_unit == "g":
|
| 46 |
+
final = GB * size_value
|
| 47 |
+
else:
|
| 48 |
+
raise ValueError(f"Invalid size unit: {size_unit}. Use 'k', 'm', or 'g'.")
|
| 49 |
+
|
| 50 |
+
return final
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
def compress_file(
|
| 54 |
+
input_file,
|
| 55 |
+
dtype="",
|
| 56 |
+
streaming_chunk_size=1048576,
|
| 57 |
+
delete=False,
|
| 58 |
+
force=False,
|
| 59 |
+
):
|
| 60 |
+
import zipnn
|
| 61 |
+
|
| 62 |
+
streaming_chunk_size = parse_streaming_chunk_size(streaming_chunk_size)
|
| 63 |
+
full_path = input_file
|
| 64 |
+
if not os.path.exists(full_path):
|
| 65 |
+
print("File not found")
|
| 66 |
+
return
|
| 67 |
+
if delete:
|
| 68 |
+
print(f"Deleting {full_path}...")
|
| 69 |
+
os.remove(full_path)
|
| 70 |
+
else:
|
| 71 |
+
compressed_path = full_path + ".znn"
|
| 72 |
+
if not force and os.path.exists(compressed_path):
|
| 73 |
+
user_input = (
|
| 74 |
+
input(f"{compressed_path} already exists; overwrite (y/n)? ").strip().lower()
|
| 75 |
+
)
|
| 76 |
+
if user_input not in ("yes", "y"):
|
| 77 |
+
print(f"Skipping {full_path}...")
|
| 78 |
+
return
|
| 79 |
+
print(f"Compressing {full_path}...")
|
| 80 |
+
#
|
| 81 |
+
output_file = input_file + ".znn"
|
| 82 |
+
if dtype:
|
| 83 |
+
zpn = zipnn.ZipNN(
|
| 84 |
+
bytearray_dtype="float32",
|
| 85 |
+
is_streaming=True,
|
| 86 |
+
streaming_chunk_kb=streaming_chunk_size,
|
| 87 |
+
)
|
| 88 |
+
else:
|
| 89 |
+
zpn = zipnn.ZipNN(
|
| 90 |
+
is_streaming=True,
|
| 91 |
+
streaming_chunk_kb=streaming_chunk_size,
|
| 92 |
+
)
|
| 93 |
+
file_size_before = 0
|
| 94 |
+
file_size_after = 0
|
| 95 |
+
start_time = time.time()
|
| 96 |
+
with open(input_file, "rb") as infile, open(output_file, "wb") as outfile:
|
| 97 |
+
chunk = infile.read()
|
| 98 |
+
file_size_before += len(chunk)
|
| 99 |
+
compressed_chunk = zpn.compress(chunk)
|
| 100 |
+
if compressed_chunk:
|
| 101 |
+
file_size_after += len(compressed_chunk)
|
| 102 |
+
outfile.write(compressed_chunk)
|
| 103 |
+
end_time = time.time() - start_time
|
| 104 |
+
print(f"Compressed {input_file} to {output_file}")
|
| 105 |
+
print(
|
| 106 |
+
f"Original size: {file_size_before/GB:.02f}GB size after compression: {file_size_after/GB:.02f}GB, Remaining size is {file_size_after/file_size_before*100:.02f}% of original, time: {end_time:.02f}"
|
| 107 |
+
)
|
| 108 |
+
|
| 109 |
+
|
| 110 |
+
if __name__ == "__main__":
|
| 111 |
+
if len(sys.argv) < 2:
|
| 112 |
+
print("Usage: python compress_files.py <suffix>")
|
| 113 |
+
print("Example: python compress_files.py 'safetensors'")
|
| 114 |
+
sys.exit(1)
|
| 115 |
+
|
| 116 |
+
parser = argparse.ArgumentParser(description="Enter a file path to compress.")
|
| 117 |
+
parser.add_argument(
|
| 118 |
+
"input_file",
|
| 119 |
+
type=str,
|
| 120 |
+
help="Specify the path to the file to compress.",
|
| 121 |
+
)
|
| 122 |
+
parser.add_argument(
|
| 123 |
+
"--float32",
|
| 124 |
+
action="store_true",
|
| 125 |
+
help="A flag that triggers float32 compression",
|
| 126 |
+
)
|
| 127 |
+
parser.add_argument(
|
| 128 |
+
"--streaming_chunk_size",
|
| 129 |
+
type=str,
|
| 130 |
+
help="An optional streaming chunk size. The format is int (for size in Bytes) or int+KB/MB/GB. Default is 1MB",
|
| 131 |
+
)
|
| 132 |
+
parser.add_argument(
|
| 133 |
+
"--delete",
|
| 134 |
+
action="store_true",
|
| 135 |
+
help="A flag that triggers deletion of a single file instead of compression",
|
| 136 |
+
)
|
| 137 |
+
parser.add_argument(
|
| 138 |
+
"--force",
|
| 139 |
+
action="store_true",
|
| 140 |
+
help="A flag that forces overwriting when compressing.",
|
| 141 |
+
)
|
| 142 |
+
args = parser.parse_args()
|
| 143 |
+
optional_kwargs = {}
|
| 144 |
+
if args.float32:
|
| 145 |
+
optional_kwargs["dtype"] = 32
|
| 146 |
+
if args.streaming_chunk_size is not None:
|
| 147 |
+
optional_kwargs["streaming_chunk_size"] = args.streaming_chunk_size
|
| 148 |
+
if args.delete:
|
| 149 |
+
optional_kwargs["delete"] = args.delete
|
| 150 |
+
if args.force:
|
| 151 |
+
optional_kwargs["force"] = args.force
|
| 152 |
+
|
| 153 |
+
check_and_install_zipnn()
|
| 154 |
+
compress_file(args.input_file, **optional_kwargs)
|
zipnn_compress_path.py
ADDED
|
@@ -0,0 +1,253 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import subprocess
|
| 3 |
+
import sys
|
| 4 |
+
import argparse
|
| 5 |
+
from concurrent.futures import (
|
| 6 |
+
ProcessPoolExecutor,
|
| 7 |
+
as_completed,
|
| 8 |
+
)
|
| 9 |
+
from zipnn_compress_file import compress_file
|
| 10 |
+
import zipnn
|
| 11 |
+
|
| 12 |
+
sys.path.append(
|
| 13 |
+
os.path.abspath(
|
| 14 |
+
os.path.join(
|
| 15 |
+
os.path.dirname(__file__), ".."
|
| 16 |
+
)
|
| 17 |
+
)
|
| 18 |
+
)
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
KB = 1024
|
| 22 |
+
MB = 1024 * 1024
|
| 23 |
+
GB = 1024 * 1024 * 1024
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
def check_and_install_zipnn():
|
| 27 |
+
try:
|
| 28 |
+
import zipnn
|
| 29 |
+
except ImportError:
|
| 30 |
+
print("zipnn not found. Installing...")
|
| 31 |
+
subprocess.check_call(
|
| 32 |
+
[
|
| 33 |
+
sys.executable,
|
| 34 |
+
"-m",
|
| 35 |
+
"pip",
|
| 36 |
+
"install",
|
| 37 |
+
"zipnn",
|
| 38 |
+
"--upgrade",
|
| 39 |
+
]
|
| 40 |
+
)
|
| 41 |
+
import zipnn
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
def parse_streaming_chunk_size(
|
| 45 |
+
streaming_chunk_size,
|
| 46 |
+
):
|
| 47 |
+
if str(streaming_chunk_size).isdigit():
|
| 48 |
+
final = int(streaming_chunk_size)
|
| 49 |
+
else:
|
| 50 |
+
size_value = int(
|
| 51 |
+
streaming_chunk_size[:-2]
|
| 52 |
+
)
|
| 53 |
+
size_unit = streaming_chunk_size[
|
| 54 |
+
-2
|
| 55 |
+
].lower()
|
| 56 |
+
|
| 57 |
+
if size_unit == "k":
|
| 58 |
+
final = KB * size_value
|
| 59 |
+
elif size_unit == "m":
|
| 60 |
+
final = MB * size_value
|
| 61 |
+
elif size_unit == "g":
|
| 62 |
+
final = GB * size_value
|
| 63 |
+
else:
|
| 64 |
+
raise ValueError(
|
| 65 |
+
f"Invalid size unit: {size_unit}. Use 'k', 'm', or 'g'."
|
| 66 |
+
)
|
| 67 |
+
|
| 68 |
+
return final
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
def compress_files_with_suffix(
|
| 72 |
+
suffix,
|
| 73 |
+
dtype="",
|
| 74 |
+
streaming_chunk_size=1048576,
|
| 75 |
+
path=".",
|
| 76 |
+
delete=False,
|
| 77 |
+
r=False,
|
| 78 |
+
force=False,
|
| 79 |
+
max_processes=1,
|
| 80 |
+
):
|
| 81 |
+
|
| 82 |
+
file_list = []
|
| 83 |
+
streaming_chunk_size = (
|
| 84 |
+
parse_streaming_chunk_size(
|
| 85 |
+
streaming_chunk_size
|
| 86 |
+
)
|
| 87 |
+
)
|
| 88 |
+
directories_to_search = (
|
| 89 |
+
os.walk(path)
|
| 90 |
+
if r
|
| 91 |
+
else [(path, [], os.listdir(path))]
|
| 92 |
+
)
|
| 93 |
+
files_found = False
|
| 94 |
+
for root, _, files in directories_to_search:
|
| 95 |
+
for file_name in files:
|
| 96 |
+
if file_name.endswith(suffix):
|
| 97 |
+
compressed_path = (
|
| 98 |
+
file_name + ".znn"
|
| 99 |
+
)
|
| 100 |
+
if not force and os.path.exists(
|
| 101 |
+
compressed_path
|
| 102 |
+
):
|
| 103 |
+
user_input = (
|
| 104 |
+
input(
|
| 105 |
+
f"{compressed_path} already exists; overwrite (y/n)? "
|
| 106 |
+
)
|
| 107 |
+
.strip()
|
| 108 |
+
.lower()
|
| 109 |
+
)
|
| 110 |
+
if user_input not in (
|
| 111 |
+
"y",
|
| 112 |
+
"yes",
|
| 113 |
+
):
|
| 114 |
+
print(
|
| 115 |
+
f"Skipping {file_name}..."
|
| 116 |
+
)
|
| 117 |
+
continue
|
| 118 |
+
files_found = True
|
| 119 |
+
full_path = os.path.join(
|
| 120 |
+
root, file_name
|
| 121 |
+
)
|
| 122 |
+
file_list.append(full_path)
|
| 123 |
+
|
| 124 |
+
with ProcessPoolExecutor(
|
| 125 |
+
max_workers=max_processes
|
| 126 |
+
) as executor:
|
| 127 |
+
future_to_file = {
|
| 128 |
+
executor.submit(
|
| 129 |
+
compress_file,
|
| 130 |
+
file,
|
| 131 |
+
dtype,
|
| 132 |
+
streaming_chunk_size,
|
| 133 |
+
delete,
|
| 134 |
+
True,
|
| 135 |
+
): file
|
| 136 |
+
for file in file_list[:max_processes]
|
| 137 |
+
}
|
| 138 |
+
file_list = file_list[max_processes:]
|
| 139 |
+
while future_to_file:
|
| 140 |
+
for future in as_completed(
|
| 141 |
+
future_to_file
|
| 142 |
+
):
|
| 143 |
+
file = future_to_file.pop(future)
|
| 144 |
+
|
| 145 |
+
try:
|
| 146 |
+
future.result()
|
| 147 |
+
except Exception as exc:
|
| 148 |
+
print(
|
| 149 |
+
f"File {file} generated an exception: {exc}"
|
| 150 |
+
)
|
| 151 |
+
|
| 152 |
+
if file_list:
|
| 153 |
+
next_file = file_list.pop(0)
|
| 154 |
+
future_to_file[
|
| 155 |
+
executor.submit(
|
| 156 |
+
compress_file,
|
| 157 |
+
next_file,
|
| 158 |
+
dtype,
|
| 159 |
+
streaming_chunk_size,
|
| 160 |
+
delete,
|
| 161 |
+
True,
|
| 162 |
+
)
|
| 163 |
+
] = next_file
|
| 164 |
+
|
| 165 |
+
if not files_found:
|
| 166 |
+
print(
|
| 167 |
+
f"No files with the suffix '{suffix}' found."
|
| 168 |
+
)
|
| 169 |
+
|
| 170 |
+
|
| 171 |
+
if __name__ == "__main__":
|
| 172 |
+
if len(sys.argv) < 2:
|
| 173 |
+
print(
|
| 174 |
+
"Usage: python compress_files.py <suffix>"
|
| 175 |
+
)
|
| 176 |
+
print(
|
| 177 |
+
"Example: python compress_files.py 'safetensors'"
|
| 178 |
+
)
|
| 179 |
+
sys.exit(1)
|
| 180 |
+
|
| 181 |
+
parser = argparse.ArgumentParser(
|
| 182 |
+
description="Enter a suffix to compress, (optional) dtype, (optional) streaming chunk size, (optional) path to files."
|
| 183 |
+
)
|
| 184 |
+
parser.add_argument(
|
| 185 |
+
"suffix",
|
| 186 |
+
type=str,
|
| 187 |
+
help="Specify the file suffix to compress all files with that suffix. If a single file name is provided, only that file will be compressed.",
|
| 188 |
+
)
|
| 189 |
+
parser.add_argument(
|
| 190 |
+
"--float32",
|
| 191 |
+
action="store_true",
|
| 192 |
+
help="A flag that triggers float32 compression",
|
| 193 |
+
)
|
| 194 |
+
parser.add_argument(
|
| 195 |
+
"--streaming_chunk_size",
|
| 196 |
+
type=str,
|
| 197 |
+
help="An optional streaming chunk size. The format is int (for size in Bytes) or int+KB/MB/GB. Default is 1MB",
|
| 198 |
+
)
|
| 199 |
+
parser.add_argument(
|
| 200 |
+
"--path",
|
| 201 |
+
type=str,
|
| 202 |
+
help="Path to files to compress",
|
| 203 |
+
)
|
| 204 |
+
parser.add_argument(
|
| 205 |
+
"--delete",
|
| 206 |
+
action="store_true",
|
| 207 |
+
help="A flag that triggers deletion of a single file instead of compression",
|
| 208 |
+
)
|
| 209 |
+
parser.add_argument(
|
| 210 |
+
"-r",
|
| 211 |
+
action="store_true",
|
| 212 |
+
help="A flag that triggers recursive search on all subdirectories",
|
| 213 |
+
)
|
| 214 |
+
parser.add_argument(
|
| 215 |
+
"--recursive",
|
| 216 |
+
action="store_true",
|
| 217 |
+
help="A flag that triggers recursive search on all subdirectories",
|
| 218 |
+
)
|
| 219 |
+
parser.add_argument(
|
| 220 |
+
"--force",
|
| 221 |
+
action="store_true",
|
| 222 |
+
help="A flag that forces overwriting when compressing.",
|
| 223 |
+
)
|
| 224 |
+
parser.add_argument(
|
| 225 |
+
"--max_processes",
|
| 226 |
+
type=int,
|
| 227 |
+
help="The amount of maximum processes.",
|
| 228 |
+
)
|
| 229 |
+
args = parser.parse_args()
|
| 230 |
+
optional_kwargs = {}
|
| 231 |
+
if args.float32:
|
| 232 |
+
optional_kwargs["dtype"] = 32
|
| 233 |
+
if args.streaming_chunk_size is not None:
|
| 234 |
+
optional_kwargs[
|
| 235 |
+
"streaming_chunk_size"
|
| 236 |
+
] = args.streaming_chunk_size
|
| 237 |
+
if args.path is not None:
|
| 238 |
+
optional_kwargs["path"] = args.path
|
| 239 |
+
if args.delete:
|
| 240 |
+
optional_kwargs["delete"] = args.delete
|
| 241 |
+
if args.r or args.recursive:
|
| 242 |
+
optional_kwargs["r"] = args.r
|
| 243 |
+
if args.force:
|
| 244 |
+
optional_kwargs["force"] = args.force
|
| 245 |
+
if args.max_processes:
|
| 246 |
+
optional_kwargs["max_processes"] = (
|
| 247 |
+
args.max_processes
|
| 248 |
+
)
|
| 249 |
+
|
| 250 |
+
check_and_install_zipnn()
|
| 251 |
+
compress_files_with_suffix(
|
| 252 |
+
args.suffix, **optional_kwargs
|
| 253 |
+
)
|
zipnn_decompress_file.py
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import subprocess
|
| 3 |
+
import sys
|
| 4 |
+
import argparse
|
| 5 |
+
|
| 6 |
+
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
def check_and_install_zipnn():
|
| 10 |
+
try:
|
| 11 |
+
import zipnn
|
| 12 |
+
except ImportError:
|
| 13 |
+
print("zipnn not found. Installing...")
|
| 14 |
+
subprocess.check_call([sys.executable, "-m", "pip", "install", "zipnn"])
|
| 15 |
+
import zipnn
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
def decompress_file(input_file, dtype="", delete=False, force=False):
|
| 19 |
+
import zipnn
|
| 20 |
+
|
| 21 |
+
if not input_file.endswith(".znn"):
|
| 22 |
+
raise ValueError("Input file does not have the '.znn' suffix")
|
| 23 |
+
|
| 24 |
+
if os.path.exists(input_file):
|
| 25 |
+
if delete:
|
| 26 |
+
print(f"Deleting {input_file}...")
|
| 27 |
+
os.remove(input_file)
|
| 28 |
+
else:
|
| 29 |
+
decompressed_path = input_file[:-4]
|
| 30 |
+
if not force and os.path.exists(decompressed_path):
|
| 31 |
+
|
| 32 |
+
user_input = (
|
| 33 |
+
input(f"{decompressed_path} already exists; overwrite (y/n)? ").strip().lower()
|
| 34 |
+
)
|
| 35 |
+
|
| 36 |
+
if user_input not in ("yes", "y"):
|
| 37 |
+
print(f"Skipping {input_file}...")
|
| 38 |
+
return
|
| 39 |
+
print(f"Decompressing {input_file}...")
|
| 40 |
+
|
| 41 |
+
output_file = input_file[:-4]
|
| 42 |
+
|
| 43 |
+
if dtype:
|
| 44 |
+
zpn = zipnn.ZipNN(is_streaming=True, bytearray_dtype="float32")
|
| 45 |
+
else:
|
| 46 |
+
zpn = zipnn.ZipNN(is_streaming=True)
|
| 47 |
+
|
| 48 |
+
with open(input_file, "rb") as infile, open(output_file, "wb") as outfile:
|
| 49 |
+
d_data = b""
|
| 50 |
+
chunk = infile.read()
|
| 51 |
+
d_data += zpn.decompress(chunk)
|
| 52 |
+
outfile.write(d_data)
|
| 53 |
+
print(f"Decompressed {input_file} to {output_file}")
|
| 54 |
+
|
| 55 |
+
else:
|
| 56 |
+
print(f"Error: The file {input_file} does not exist.")
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
if __name__ == "__main__":
|
| 60 |
+
check_and_install_zipnn()
|
| 61 |
+
|
| 62 |
+
parser = argparse.ArgumentParser(description="Enter a file path to decompress.")
|
| 63 |
+
parser.add_argument("input_file", type=str, help="Specify the path to the file to decompress.")
|
| 64 |
+
parser.add_argument(
|
| 65 |
+
"--float32", action="store_true", help="A flag that triggers float32 compression."
|
| 66 |
+
)
|
| 67 |
+
parser.add_argument(
|
| 68 |
+
"--delete",
|
| 69 |
+
action="store_true",
|
| 70 |
+
help="A flag that triggers deletion of a single compressed file instead of decompression",
|
| 71 |
+
)
|
| 72 |
+
parser.add_argument(
|
| 73 |
+
"--force", action="store_true", help="A flag that forces overwriting when decompressing."
|
| 74 |
+
)
|
| 75 |
+
args = parser.parse_args()
|
| 76 |
+
optional_kwargs = {}
|
| 77 |
+
if args.float32:
|
| 78 |
+
optional_kwargs["dtype"] = 32
|
| 79 |
+
if args.delete:
|
| 80 |
+
optional_kwargs["delete"] = args.delete
|
| 81 |
+
if args.force:
|
| 82 |
+
optional_kwargs["force"] = args.force
|
| 83 |
+
|
| 84 |
+
decompress_file(args.input_file, **optional_kwargs)
|
zipnn_decompress_path.py
ADDED
|
@@ -0,0 +1,184 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import sys
|
| 3 |
+
import argparse
|
| 4 |
+
import subprocess
|
| 5 |
+
import zipnn
|
| 6 |
+
from concurrent.futures import (
|
| 7 |
+
ProcessPoolExecutor,
|
| 8 |
+
as_completed,
|
| 9 |
+
)
|
| 10 |
+
from zipnn_decompress_file import (
|
| 11 |
+
decompress_file,
|
| 12 |
+
)
|
| 13 |
+
|
| 14 |
+
sys.path.append(
|
| 15 |
+
os.path.abspath(
|
| 16 |
+
os.path.join(
|
| 17 |
+
os.path.dirname(__file__),
|
| 18 |
+
"..",
|
| 19 |
+
)
|
| 20 |
+
)
|
| 21 |
+
)
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
def check_and_install_zipnn():
|
| 25 |
+
try:
|
| 26 |
+
import zipnn
|
| 27 |
+
except ImportError:
|
| 28 |
+
print("zipnn not found. Installing...")
|
| 29 |
+
subprocess.check_call(
|
| 30 |
+
[
|
| 31 |
+
sys.executable,
|
| 32 |
+
"-m",
|
| 33 |
+
"pip",
|
| 34 |
+
"install",
|
| 35 |
+
"zipnn",
|
| 36 |
+
]
|
| 37 |
+
)
|
| 38 |
+
import zipnn
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
def decompress_zpn_files(
|
| 42 |
+
dtype="",
|
| 43 |
+
path=".",
|
| 44 |
+
delete=False,
|
| 45 |
+
force=False,
|
| 46 |
+
max_processes=1,
|
| 47 |
+
):
|
| 48 |
+
|
| 49 |
+
file_list = []
|
| 50 |
+
directories_to_search = [
|
| 51 |
+
(
|
| 52 |
+
path,
|
| 53 |
+
[],
|
| 54 |
+
os.listdir(path),
|
| 55 |
+
)
|
| 56 |
+
]
|
| 57 |
+
for (
|
| 58 |
+
root,
|
| 59 |
+
_,
|
| 60 |
+
files,
|
| 61 |
+
) in directories_to_search:
|
| 62 |
+
for file_name in files:
|
| 63 |
+
if file_name.endswith(".znn"):
|
| 64 |
+
decompressed_path = file_name[:-4]
|
| 65 |
+
if not force and os.path.exists(
|
| 66 |
+
decompressed_path
|
| 67 |
+
):
|
| 68 |
+
user_input = (
|
| 69 |
+
input(
|
| 70 |
+
f"{decompressed_path} already exists; overwrite (y/n)? "
|
| 71 |
+
)
|
| 72 |
+
.strip()
|
| 73 |
+
.lower()
|
| 74 |
+
)
|
| 75 |
+
if user_input not in (
|
| 76 |
+
"y",
|
| 77 |
+
"yes",
|
| 78 |
+
):
|
| 79 |
+
print(
|
| 80 |
+
f"Skipping {file_name}..."
|
| 81 |
+
)
|
| 82 |
+
continue
|
| 83 |
+
full_path = os.path.join(
|
| 84 |
+
root,
|
| 85 |
+
file_name,
|
| 86 |
+
)
|
| 87 |
+
file_list.append(full_path)
|
| 88 |
+
|
| 89 |
+
with ProcessPoolExecutor(
|
| 90 |
+
max_workers=max_processes
|
| 91 |
+
) as executor:
|
| 92 |
+
for file in file_list[:max_processes]:
|
| 93 |
+
future_to_file = {
|
| 94 |
+
executor.submit(
|
| 95 |
+
decompress_file,
|
| 96 |
+
file,
|
| 97 |
+
dtype,
|
| 98 |
+
delete,
|
| 99 |
+
True,
|
| 100 |
+
): file
|
| 101 |
+
for file in file_list[
|
| 102 |
+
:max_processes
|
| 103 |
+
]
|
| 104 |
+
}
|
| 105 |
+
|
| 106 |
+
file_list = file_list[max_processes:]
|
| 107 |
+
while future_to_file:
|
| 108 |
+
|
| 109 |
+
for future in as_completed(
|
| 110 |
+
future_to_file
|
| 111 |
+
):
|
| 112 |
+
file = future_to_file.pop(
|
| 113 |
+
future
|
| 114 |
+
)
|
| 115 |
+
try:
|
| 116 |
+
future.result()
|
| 117 |
+
except Exception as exc:
|
| 118 |
+
print(
|
| 119 |
+
f"File {file} generated an exception: {exc}"
|
| 120 |
+
)
|
| 121 |
+
|
| 122 |
+
if file_list:
|
| 123 |
+
next_file = file_list.pop(
|
| 124 |
+
0
|
| 125 |
+
)
|
| 126 |
+
future_to_file[
|
| 127 |
+
executor.submit(
|
| 128 |
+
decompress_file,
|
| 129 |
+
next_file,
|
| 130 |
+
dtype,
|
| 131 |
+
delete,
|
| 132 |
+
True,
|
| 133 |
+
)
|
| 134 |
+
] = next_file
|
| 135 |
+
#
|
| 136 |
+
|
| 137 |
+
|
| 138 |
+
if __name__ == "__main__":
|
| 139 |
+
check_and_install_zipnn()
|
| 140 |
+
|
| 141 |
+
parser = argparse.ArgumentParser(
|
| 142 |
+
description="Compresses all .znn files. (optional) dtype."
|
| 143 |
+
)
|
| 144 |
+
parser.add_argument(
|
| 145 |
+
"--float32",
|
| 146 |
+
action="store_true",
|
| 147 |
+
help="A flag that triggers float32 compression.",
|
| 148 |
+
)
|
| 149 |
+
parser.add_argument(
|
| 150 |
+
"--path",
|
| 151 |
+
type=str,
|
| 152 |
+
help="Path to folder of files to decompress. If left empty, checks current folder.",
|
| 153 |
+
)
|
| 154 |
+
parser.add_argument(
|
| 155 |
+
"--delete",
|
| 156 |
+
action="store_true",
|
| 157 |
+
help="A flag that triggers deletion of a single compressed file instead of decompression",
|
| 158 |
+
)
|
| 159 |
+
parser.add_argument(
|
| 160 |
+
"--force",
|
| 161 |
+
action="store_true",
|
| 162 |
+
help="A flag that forces overwriting when decompressing.",
|
| 163 |
+
)
|
| 164 |
+
parser.add_argument(
|
| 165 |
+
"--max_processes",
|
| 166 |
+
type=int,
|
| 167 |
+
help="The amount of maximum processes.",
|
| 168 |
+
)
|
| 169 |
+
args = parser.parse_args()
|
| 170 |
+
optional_kwargs = {}
|
| 171 |
+
if args.float32:
|
| 172 |
+
optional_kwargs["dtype"] = 32
|
| 173 |
+
if args.path is not None:
|
| 174 |
+
optional_kwargs["path"] = args.path
|
| 175 |
+
if args.delete:
|
| 176 |
+
optional_kwargs["delete"] = args.delete
|
| 177 |
+
if args.force:
|
| 178 |
+
optional_kwargs["force"] = args.force
|
| 179 |
+
if args.max_processes:
|
| 180 |
+
optional_kwargs["max_processes"] = (
|
| 181 |
+
args.max_processes
|
| 182 |
+
)
|
| 183 |
+
|
| 184 |
+
decompress_zpn_files(**optional_kwargs)
|