mirror of
https://github.com/ggml-org/llama.cpp.git
synced 2025-10-27 08:21:30 +00:00
model-conversion : fix pyright errors (#15770)
This commit addresses type errors reported by pyright in the model conversion scripts.
This commit is contained in:
@@ -3,11 +3,10 @@
|
|||||||
import argparse
|
import argparse
|
||||||
import os
|
import os
|
||||||
import importlib
|
import importlib
|
||||||
import sys
|
|
||||||
import torch
|
import torch
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
||||||
from transformers import AutoTokenizer, AutoConfig, AutoModel, AutoModelForCausalLM
|
from transformers import AutoTokenizer, AutoConfig, AutoModelForCausalLM
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
unreleased_model_name = os.getenv('UNRELEASED_MODEL_NAME')
|
unreleased_model_name = os.getenv('UNRELEASED_MODEL_NAME')
|
||||||
@@ -43,6 +42,8 @@ if unreleased_model_name:
|
|||||||
model = model_class.from_pretrained(model_path)
|
model = model_class.from_pretrained(model_path)
|
||||||
except (ImportError, AttributeError) as e:
|
except (ImportError, AttributeError) as e:
|
||||||
print(f"Failed to import or load model: {e}")
|
print(f"Failed to import or load model: {e}")
|
||||||
|
print("Falling back to AutoModelForCausalLM")
|
||||||
|
model = AutoModelForCausalLM.from_pretrained(model_path)
|
||||||
else:
|
else:
|
||||||
model = AutoModelForCausalLM.from_pretrained(model_path)
|
model = AutoModelForCausalLM.from_pretrained(model_path)
|
||||||
print(f"Model class: {type(model)}")
|
print(f"Model class: {type(model)}")
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ if os.path.exists(index_path):
|
|||||||
file_path = os.path.join(model_path, file_name)
|
file_path = os.path.join(model_path, file_name)
|
||||||
print(f"\n--- From {file_name} ---")
|
print(f"\n--- From {file_name} ---")
|
||||||
|
|
||||||
with safe_open(file_path, framework="pt") as f:
|
with safe_open(file_path, framework="pt") as f: # type: ignore
|
||||||
for tensor_name in sorted(tensor_names):
|
for tensor_name in sorted(tensor_names):
|
||||||
tensor = f.get_tensor(tensor_name)
|
tensor = f.get_tensor(tensor_name)
|
||||||
print(f"- {tensor_name} : shape = {tensor.shape}, dtype = {tensor.dtype}")
|
print(f"- {tensor_name} : shape = {tensor.shape}, dtype = {tensor.dtype}")
|
||||||
@@ -49,7 +49,7 @@ elif os.path.exists(single_file_path):
|
|||||||
# Single file model (original behavior)
|
# Single file model (original behavior)
|
||||||
print("Single-file model detected")
|
print("Single-file model detected")
|
||||||
|
|
||||||
with safe_open(single_file_path, framework="pt") as f:
|
with safe_open(single_file_path, framework="pt") as f: # type: ignore
|
||||||
keys = f.keys()
|
keys = f.keys()
|
||||||
print("Tensors in model:")
|
print("Tensors in model:")
|
||||||
for key in sorted(keys):
|
for key in sorted(keys):
|
||||||
|
|||||||
Reference in New Issue
Block a user