add fp8 version
Browse files
convert_fp8_simple.py
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
from safetensors import safe_open
|
| 3 |
+
from safetensors.torch import save_file
|
| 4 |
+
from tqdm import tqdm
|
| 5 |
+
import argparse
|
| 6 |
+
import os
|
| 7 |
+
|
| 8 |
+
def convert_to_fp8_simple(input_path, output_path=None):
|
| 9 |
+
"""
|
| 10 |
+
LoRAファイルを通常のFP8(非スケール版)に変換
|
| 11 |
+
"""
|
| 12 |
+
if output_path is None:
|
| 13 |
+
# 出力ファイル名を自動生成
|
| 14 |
+
base_name = os.path.splitext(input_path)[0]
|
| 15 |
+
output_path = f"{base_name}_fp8.safetensors"
|
| 16 |
+
|
| 17 |
+
print(f"入力ファイル: {input_path}")
|
| 18 |
+
print(f"出力ファイル: {output_path}")
|
| 19 |
+
|
| 20 |
+
# メタデータを読み込む
|
| 21 |
+
metadata = {}
|
| 22 |
+
with safe_open(input_path, framework="pt", device="cpu") as f:
|
| 23 |
+
if f.metadata() is not None:
|
| 24 |
+
metadata = f.metadata()
|
| 25 |
+
|
| 26 |
+
# テンソルを変換
|
| 27 |
+
converted_tensors = {}
|
| 28 |
+
print("テンソルを変換中...")
|
| 29 |
+
|
| 30 |
+
with safe_open(input_path, framework="pt", device="cpu") as f:
|
| 31 |
+
for key in tqdm(f.keys(), desc="変換中"):
|
| 32 |
+
tensor = f.get_tensor(key)
|
| 33 |
+
# シンプルにFP8に変換
|
| 34 |
+
converted_tensors[key] = tensor.to(torch.float8_e4m3fn)
|
| 35 |
+
|
| 36 |
+
# メタデータに形式情報を追加
|
| 37 |
+
metadata["format"] = "pt"
|
| 38 |
+
metadata["fp8_type"] = "simple" # fp8-scaledではないことを明示
|
| 39 |
+
|
| 40 |
+
# 保存
|
| 41 |
+
print(f"変換したモデルを保存中: {output_path}")
|
| 42 |
+
save_file(converted_tensors, output_path, metadata=metadata)
|
| 43 |
+
|
| 44 |
+
# ファイルサイズの比較
|
| 45 |
+
original_size = os.path.getsize(input_path) / (1024**3) # GB
|
| 46 |
+
converted_size = os.path.getsize(output_path) / (1024**3) # GB
|
| 47 |
+
|
| 48 |
+
print(f"\n✅ 変換完了!")
|
| 49 |
+
print(f"元のサイズ: {original_size:.2f} GB")
|
| 50 |
+
print(f"変換後: {converted_size:.2f} GB")
|
| 51 |
+
print(f"削減率: {(1 - converted_size/original_size)*100:.1f}%")
|
| 52 |
+
|
| 53 |
+
if __name__ == "__main__":
|
| 54 |
+
parser = argparse.ArgumentParser(description="LoRAファイルを通常のFP8に変換")
|
| 55 |
+
parser.add_argument("input", type=str, help="入力LoRAファイルのパス")
|
| 56 |
+
parser.add_argument("--output", "-o", type=str, default=None,
|
| 57 |
+
help="出力ファイルのパス(省略時は自動生成)")
|
| 58 |
+
|
| 59 |
+
args = parser.parse_args()
|
| 60 |
+
|
| 61 |
+
convert_to_fp8_simple(args.input, args.output)
|
wan2.1/ChronoEdit_480_extracted_lora_rank2048_adaptive_fro_0.95_fp8.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:cbc1245f0a6224b401eae00f5d6a8fe6356a65c0eb21286bd9c108aadf5d51a8
|
| 3 |
+
size 10563734344
|
wan2.1/README.md
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
# **LoRA Files**
|
| 2 |
## ChronoEdit
|
| 3 |
-
**ChronoEdit_480_extracted_lora_rank2048_adaptive_fro_0.95_fp16.safetensors**
|
|
|
|
| 4 |
This is a LoRA created using the LoraExtractKJ node, representing the difference between the weights of ChronoEdit and wan2.1_i2v_480p_14B_fp16.safetensors. (Accuracy is approximately 80-95% at Rank 2048)
|
| 5 |
It is very large and therefore not suitable for typical LoRA use, but because it has been converted into a LoRA, it can be applied to T2V models, and I have confirmed that it can be used when using VACE. (There may be some degradation in quality.)
|
| 6 |
|
|
|
|
| 1 |
# **LoRA Files**
|
| 2 |
## ChronoEdit
|
| 3 |
+
**ChronoEdit_480_extracted_lora_rank2048_adaptive_fro_0.95_fp16.safetensors**
|
| 4 |
+
**ChronoEdit_480_extracted_lora_rank2048_adaptive_fro_0.95_fp8.safetensors** <BR>
|
| 5 |
This is a LoRA created using the LoraExtractKJ node, representing the difference between the weights of ChronoEdit and wan2.1_i2v_480p_14B_fp16.safetensors. (Accuracy is approximately 80-95% at Rank 2048)
|
| 6 |
It is very large and therefore not suitable for typical LoRA use, but because it has been converted into a LoRA, it can be applied to T2V models, and I have confirmed that it can be used when using VACE. (There may be some degradation in quality.)
|
| 7 |
|