Some checks failed
Bindings Tests (Go) / ubuntu-22 (push) Failing after 31s
CI (sycl) / ubuntu-22-cmake-sycl (linux/arm/v7, icx, icpx, ON) (push) Failing after 3s
CI (sycl) / ubuntu-22-cmake-sycl (linux/ppc64le, icx, icpx, ON) (push) Failing after 2s
CI (sycl) / ubuntu-22-cmake-sycl-fp16 (linux/amd64, icx, icpx, ON) (push) Failing after 3s
CI (sycl) / ubuntu-22-cmake-sycl-fp16 (linux/arm/v7, icx, icpx, ON) (push) Failing after 3s
CI (sycl) / ubuntu-22-cmake-sycl-fp16 (linux/arm64, icx, icpx, ON) (push) Failing after 3s
CI (sycl) / ubuntu-22-cmake-sycl-fp16 (linux/ppc64le, icx, icpx, ON) (push) Failing after 3s
CI (vad) / vad (push) Failing after 3s
CI (wasm) / emscripten (Release) (push) Failing after 4s
Bindings Tests (Ruby) / ubuntu-22 (push) Failing after 37s
CI (android) / android (push) Failing after 16s
CI (android) / android_java (push) Failing after 3s
CI (clang) / ubuntu-22-clang (linux/amd64, Debug) (push) Failing after 3s
CI (clang) / ubuntu-22-clang (linux/amd64, Release) (push) Failing after 2s
CI (clang) / ubuntu-22-clang (linux/ppc64le, Debug) (push) Failing after 3s
CI (clang) / ubuntu-22-clang (linux/ppc64le, Release) (push) Failing after 3s
CI (cpu) / ggml-ci-x64-cpu-low-perf (push) Failing after 3s
CI (cpu) / ggml-ci-x64-cpu-high-perf (push) Failing after 2s
CI (gcc) / ubuntu-22-gcc (linux/amd64, Debug) (push) Failing after 3s
CI (gcc) / ubuntu-22-gcc (linux/amd64, Release) (push) Failing after 3s
CI (gcc) / ubuntu-22-gcc (linux/ppc64le, Debug) (push) Failing after 3s
CI (gcc) / ubuntu-22-gcc (linux/ppc64le, Release) (push) Failing after 4s
CI (gcc) / ubuntu-22-gcc-arm-v7 (linux/arm/v7, Debug) (push) Failing after 3s
CI (gcc) / ubuntu-22-gcc-arm-v7 (linux/arm/v7, Release) (push) Failing after 3s
CI (quantize) / quantize (push) Failing after 3s
CI (sanitize) / ubuntu-22-gcc-sanitized (ADDRESS) (push) Failing after 3s
CI (sanitize) / ubuntu-22-gcc-sanitized (THREAD) (push) Failing after 3s
CI (sanitize) / ubuntu-22-gcc-sanitized (UNDEFINED) (push) Failing after 2s
CI (sycl) / ubuntu-22-cmake-sycl (linux/amd64, icx, icpx, ON) (push) Failing after 3s
CI (sycl) / ubuntu-22-cmake-sycl (linux/arm64, icx, icpx, ON) (push) Failing after 3s
Examples WASM / deploy-wasm-github-pages (push) Failing after 3s
Examples Tests / addon_node-ubuntu-22 (20.x) (push) Failing after 3s
Examples Tests / addon_node-ubuntu-22 (22.x) (push) Failing after 2s
CI (coreml) / coreml-base-en (push) Has been cancelled
CI (self-hosted) / gpu-vulkan (push) Has been cancelled
CI (self-hosted) / npu-amd-windows (push) Has been cancelled
CI (self-hosted) / gpu-vulkan-nvidia-cm2 (push) Has been cancelled
CI (clang) / ubuntu-22-clang-arm64 (Debug) (push) Has been cancelled
CI (clang) / ubuntu-22-clang-arm64 (Release) (push) Has been cancelled
CI (self-hosted) / gpu-cuda (push) Has been cancelled
CI (self-hosted) / gpu-vulkan-nvidia-cm (push) Has been cancelled
CI (cpu) / ggml-ci-arm64-cpu-low-perf (push) Has been cancelled
CI (cpu) / ggml-ci-arm64-cpu-high-perf (push) Has been cancelled
CI (cpu) / ggml-ci-arm64-cpu-high-perf-sve (push) Has been cancelled
CI (freebsd) / freeBSD-latest (push) Has been cancelled
CI (self-hosted) / gpu-metal (push) Has been cancelled
CI (gcc) / ubuntu-22-gcc-arm64 (Debug) (push) Has been cancelled
CI (gcc) / ubuntu-22-gcc-arm64 (Release) (push) Has been cancelled
CI (macOS) / macOS-latest (generic/platform=iOS) (push) Has been cancelled
CI (macOS) / macOS-latest (generic/platform=macOS) (push) Has been cancelled
CI (macOS) / macOS-latest (generic/platform=tvOS) (push) Has been cancelled
CI (self-hosted) / npu-amd-linux (push) Has been cancelled
CI (windows) / windows-msys2 (Release, clang, clang-x86_64, CLANG64) (push) Has been cancelled
CI (windows) / windows-msys2 (Release, gcc, ucrt-x86_64, UCRT64) (push) Has been cancelled
Publish Docker image / Push Docker image to Docker Hub (map[dockerfile:.devops/main-cuda.Dockerfile platform:linux/amd64 runs_on:ubuntu-24.04 tag:main-cuda]) (push) Has been cancelled
Publish Docker image / Push Docker image to Docker Hub (map[dockerfile:.devops/main-intel.Dockerfile platform:linux/amd64 runs_on:ubuntu-24.04 tag:main-intel]) (push) Has been cancelled
Publish Docker image / Push Docker image to Docker Hub (map[dockerfile:.devops/main-musa.Dockerfile platform:linux/amd64 runs_on:ubuntu-24.04 tag:main-musa]) (push) Has been cancelled
Publish Docker image / Push Docker image to Docker Hub (map[dockerfile:.devops/main-vulkan.Dockerfile platform:linux/amd64 runs_on:ubuntu-24.04 tag:main-vulkan]) (push) Has been cancelled
Publish Docker image / Push Docker image to Docker Hub (map[dockerfile:.devops/main-vulkan.Dockerfile platform:linux/arm64 runs_on:ubuntu-24.04-arm tag:main-vulkan-arm64]) (push) Has been cancelled
Publish Docker image / Push Docker image to Docker Hub (map[dockerfile:.devops/main.Dockerfile platform:linux/amd64 runs_on:ubuntu-24.04 tag:main]) (push) Has been cancelled
Publish Docker image / Push Docker image to Docker Hub (map[dockerfile:.devops/main.Dockerfile platform:linux/arm64 runs_on:ubuntu-24.04-arm tag:main-arm64]) (push) Has been cancelled
Mark inactive issues stale / mark-issues (push) Failing after 1s
110 lines
3.5 KiB
Python
110 lines
3.5 KiB
Python
import struct
|
|
import torch
|
|
import numpy as np
|
|
from collections import OrderedDict
|
|
from pathlib import Path
|
|
import sys
|
|
|
|
if len(sys.argv) < 3:
|
|
print(
|
|
"Usage: convert-ggml-to-pt.py model.bin dir-output\n")
|
|
sys.exit(1)
|
|
|
|
fname_inp = Path(sys.argv[1])
|
|
dir_out = Path(sys.argv[2])
|
|
fname_out = dir_out / "torch-model.pt"
|
|
|
|
|
|
|
|
# Open the ggml file
|
|
with open(fname_inp, "rb") as f:
|
|
# Read magic number and hyperparameters
|
|
magic_number, n_vocab, n_audio_ctx, n_audio_state, n_audio_head, n_audio_layer, n_text_ctx, n_text_state, n_text_head, n_text_layer, n_mels, use_f16 = struct.unpack("12i", f.read(48))
|
|
print(f"Magic number: {magic_number}")
|
|
print(f"Vocab size: {n_vocab}")
|
|
print(f"Audio context size: {n_audio_ctx}")
|
|
print(f"Audio state size: {n_audio_state}")
|
|
print(f"Audio head size: {n_audio_head}")
|
|
print(f"Audio layer size: {n_audio_layer}")
|
|
print(f"Text context size: {n_text_ctx}")
|
|
print(f"Text head size: {n_text_head}")
|
|
print(f"Mel size: {n_mels}")
|
|
# Read mel filters
|
|
# mel_filters = np.fromfile(f, dtype=np.float32, count=n_mels * 2).reshape(n_mels, 2)
|
|
# print(f"Mel filters: {mel_filters}")
|
|
filters_shape_0 = struct.unpack("i", f.read(4))[0]
|
|
print(f"Filters shape 0: {filters_shape_0}")
|
|
filters_shape_1 = struct.unpack("i", f.read(4))[0]
|
|
print(f"Filters shape 1: {filters_shape_1}")
|
|
|
|
# Read tokenizer tokens
|
|
# bytes = f.read(4)
|
|
# print(bytes)
|
|
|
|
|
|
# for i in range(filters.shape[0]):
|
|
# for j in range(filters.shape[1]):
|
|
# fout.write(struct.pack("f", filters[i][j]))
|
|
mel_filters = np.zeros((filters_shape_0, filters_shape_1))
|
|
|
|
for i in range(filters_shape_0):
|
|
for j in range(filters_shape_1):
|
|
mel_filters[i][j] = struct.unpack("f", f.read(4))[0]
|
|
|
|
bytes_data = f.read(4)
|
|
num_tokens = struct.unpack("i", bytes_data)[0]
|
|
tokens = {}
|
|
|
|
|
|
for _ in range(num_tokens):
|
|
token_len = struct.unpack("i", f.read(4))[0]
|
|
token = f.read(token_len)
|
|
tokens[token] = {}
|
|
|
|
# Read model variables
|
|
model_state_dict = OrderedDict()
|
|
while True:
|
|
try:
|
|
n_dims, name_length, ftype = struct.unpack("iii", f.read(12))
|
|
except struct.error:
|
|
break # End of file
|
|
dims = [struct.unpack("i", f.read(4))[0] for _ in range(n_dims)]
|
|
dims = dims[::-1]
|
|
name = f.read(name_length).decode("utf-8")
|
|
if ftype == 1: # f16
|
|
data = np.fromfile(f, dtype=np.float16, count=np.prod(dims)).reshape(dims)
|
|
else: # f32
|
|
data = np.fromfile(f, dtype=np.float32, count=np.prod(dims)).reshape(dims)
|
|
|
|
|
|
if name in ["encoder.conv1.bias", "encoder.conv2.bias"]:
|
|
|
|
data = data[:, 0]
|
|
|
|
|
|
model_state_dict[name] = torch.from_numpy(data)
|
|
|
|
# Now you have the model's state_dict stored in model_state_dict
|
|
# You can load this state_dict into a model with the same architecture
|
|
|
|
# dims = ModelDimensions(**checkpoint["dims"])
|
|
# model = Whisper(dims)
|
|
from whisper import Whisper, ModelDimensions
|
|
dims = ModelDimensions(
|
|
n_mels=n_mels,
|
|
n_audio_ctx=n_audio_ctx,
|
|
n_audio_state=n_audio_state,
|
|
n_audio_head=n_audio_head,
|
|
n_audio_layer=n_audio_layer,
|
|
n_text_ctx=n_text_ctx,
|
|
n_text_state=n_text_state,
|
|
n_text_head=n_text_head,
|
|
n_text_layer=n_text_layer,
|
|
n_vocab=n_vocab,
|
|
)
|
|
model = Whisper(dims) # Replace with your model's class
|
|
model.load_state_dict(model_state_dict)
|
|
|
|
# Save the model in PyTorch format
|
|
torch.save(model.state_dict(), fname_out)
|