admin管理员组文章数量:1389875
I am installed the llamma3.2 model from meta directly and got it in this format
-a---- 3/10/2025 3:22 PM 209 checklist.chk
-a---- 3/10/2025 9:47 AM 6425585114 consolidated.00.pth
-a---- 3/10/2025 9:27 AM 220 params.json
-a---- 3/10/2025 9:27 AM 2183982 tokenizer.model
And I am trying to run it, but it is giving me this error
Traceback (most recent call last):
File "C:\Users\user\.llama\checkpoints\Llama3.2-3B-Instruct\LLAMA.PY", line 14, in <module>
model = LlamaForCausalLM.from_pretrained(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\user\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\transformers\modeling_utils.py", line 262, in _wrapper
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\user\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\transformers\modeling_utils.py", line 3808, in from_pretrained
raise EnvironmentError(
OSError: Error no file named pytorch_model.bin, model.safetensors, tf_model.h5, model.ckpt.index or flax_model.msgpack found in director
running this code
# Install required packages if you haven't already
# pip install torch transformers
import torch
from transformers import LlamaForCausalLM, LlamaTokenizer
# Path to your model files
model_path = "C:/Users/user/.llama/checkpoints/Llama3.2-3B-Instruct" # The folder containing the files you listed
# Load the tokenizer
tokenizer = LlamaTokenizer.from_pretrained(model_path)
# Load the model
model = LlamaForCausalLM.from_pretrained(
model_path,
torch_dtype=torch.float16, # Use float16 for efficiency
low_cpu_mem_usage=True, # Helps with memory usage
device_map="auto" # Automatically use GPU if available
)
# Generate text
def generate_text(prompt, max_length=100):
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
# Generate
with torch.no_grad():
output = model.generate(
inputs["input_ids"],
max_length=max_length,
temperature=0.7,
top_p=0.9,
do_sample=True
)
# Decode and return the generated text
return tokenizer.decode(output[0], skip_special_tokens=True)
# Test the model
response = generate_text("What is artificial intelligence?")
print(response)
From what I have seen the model format is of meta's base one but I am not sure on how to run it
I am installed the llamma3.2 model from meta directly and got it in this format
-a---- 3/10/2025 3:22 PM 209 checklist.chk
-a---- 3/10/2025 9:47 AM 6425585114 consolidated.00.pth
-a---- 3/10/2025 9:27 AM 220 params.json
-a---- 3/10/2025 9:27 AM 2183982 tokenizer.model
And I am trying to run it, but it is giving me this error
Traceback (most recent call last):
File "C:\Users\user\.llama\checkpoints\Llama3.2-3B-Instruct\LLAMA.PY", line 14, in <module>
model = LlamaForCausalLM.from_pretrained(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\user\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\transformers\modeling_utils.py", line 262, in _wrapper
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\user\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\transformers\modeling_utils.py", line 3808, in from_pretrained
raise EnvironmentError(
OSError: Error no file named pytorch_model.bin, model.safetensors, tf_model.h5, model.ckpt.index or flax_model.msgpack found in director
running this code
# Install required packages if you haven't already
# pip install torch transformers
import torch
from transformers import LlamaForCausalLM, LlamaTokenizer
# Path to your model files
model_path = "C:/Users/user/.llama/checkpoints/Llama3.2-3B-Instruct" # The folder containing the files you listed
# Load the tokenizer
tokenizer = LlamaTokenizer.from_pretrained(model_path)
# Load the model
model = LlamaForCausalLM.from_pretrained(
model_path,
torch_dtype=torch.float16, # Use float16 for efficiency
low_cpu_mem_usage=True, # Helps with memory usage
device_map="auto" # Automatically use GPU if available
)
# Generate text
def generate_text(prompt, max_length=100):
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
# Generate
with torch.no_grad():
output = model.generate(
inputs["input_ids"],
max_length=max_length,
temperature=0.7,
top_p=0.9,
do_sample=True
)
# Decode and return the generated text
return tokenizer.decode(output[0], skip_special_tokens=True)
# Test the model
response = generate_text("What is artificial intelligence?")
print(response)
From what I have seen the model format is of meta's base one but I am not sure on how to run it
Share Improve this question asked Mar 13 at 7:21 JoeJoe 234 bronze badges 2- Why not use Ollama to run the model locally? – Ifeanyi Idiaye Commented Mar 13 at 8:50
- I want to configure it manually to do a specific task – Joe Commented Mar 13 at 10:13
1 Answer
Reset to default 0It seems that your model has not been installed completely. One way can be fetch it from HuggingFace and store it in the place, like the following:
from transformers import AutoModelForCausalLM, AutoTokenizer
model_name = "meta-llama/Llama-3-8B-Instruct"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(model_name)
model.save_pretrained("C:/Users/user/.llama/checkpoints/Llama3.2-3B-Instruct")
tokenizer.save_pretrained("C:/Users/user/.llama/checkpoints/Llama3.2-3B-Instruct")
In that way, you will be sure that all files are there.
本文标签: pythonMeta llama 32 3b model local downloadStack Overflow
版权声明:本文标题:python - Meta llama 3.2 3b model local download - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744715468a2621377.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论