← 教程
AI05-27

Hugging Face 模型下载与使用

浏览模型

访问 huggingface.co/models,用任务标签(text-generation、image-classification)和语言过滤。关注 Download 排行和更新时间。

下载模型

用 huggingface_hub 库下载:huggingface-cli download meta-llama/Llama-3.2-1B --local-dir ./model。设置 HF_TOKEN 环境变量访问受限模型。

使用 Pipeline

transformers 库的 pipeline 是最简单的调用方式:pipe = pipeline('text-generation', model='./model'),一行就能跑推理。

数据集与 Space

数据集搜索技巧:用语言筛选(zh 中文)、任务筛选、尺寸筛选。Space 是即用的 AI demo,能看到源码和生产配置。

镜像加速

国内用户设置镜像源:HF_ENDPOINT=https://hf-mirror.com。或者用 modelscope.cn 上的同步镜像下载。