本文主要是介绍如何在huggingface上下载模型,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
先安装:
pip install huggingface_hub
终端登录huggingface账号:
huggingface-cli login
填写上自己的token之后现实登录成功,然后就可以下载不需要额外认证的模型
如果不能连接上huggingface,可以使用镜像网站,在终端运行:
export HUGGINGFACE_CO_RESOLVE_ENDPOINT=https://hf-mirror.com
export HF_ENDPOINT=https://hf-mirror.com
from vllm import LLM, SamplingParams# Sample prompts.
prompts = ["Hello, my name is","The president of the United States is","The capital of France is","The future of AI is",
]
# Create a sampling params object.
sampling_params = SamplingParams(temperature=0.8, top_p=0.95)# Create an LLM.
llm = LLM(model="meta-llama/Meta-Llama-3-8B")
# Generate texts from the prompts. The output is a list of RequestOutput objects
# that contain the prompt, generated text, and other information.
outputs = llm.generate(prompts, sampling_params)
# Print the outputs.
for output in outputs:prompt = output.promptgenerated_text = output.outputs[0].textprint(f"Prompt: {prompt!r}, Generated text: {generated_text!r}")
这篇关于如何在huggingface上下载模型的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!