M2 Pro安装 huggingface transformer

首先安装 conda 环境,可以参考之前安装 conda 的文章

  1. 创建新的conda 环境
conda create -n myenv python=3.10
  1. 激活 conda 环境
conda activate myenv
  1. 安装 transformer 类库
pip install transformers
  1. 安装 pytorch
conda install pytorch torchvision torchaudio cpuonly -c pytorch
  1. 确认安装成功
# test_transformers.py
try:
    from transformers import pipeline
    print("Transformers library has been successfully installed.")
except ImportError as e:
    print("An error occurred:", e)
  1. 下载 gpt2模型测试
# Import the pipeline function from the transformers library
from transformers import pipeline

# Initialize a text generation pipeline with the GPT-2 model
generator = pipeline('text-generation', model='gpt2')

# Generate text based on a prompt
generated_text = generator("Hello, my name is", max_length=30)

# Print the generated text
print(generated_text)

如果遇到以下错误,升级一下 charset

An error occurred: cannot import name ‘COMMON_SAFE_ASCII_CHARACTERS’ from ‘charset_normalizer.constant’

pip install --upgrade charset_normalizer

相关推荐

  1. M2 Pro安装 huggingface transformer

    2024-04-10 00:06:01       39 阅读
  2. 使用docker部署Kafka(MAC Apple M2 Pro)

    2024-04-10 00:06:01       53 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-04-10 00:06:01       98 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-04-10 00:06:01       106 阅读
  3. 在Django里面运行非项目文件

    2024-04-10 00:06:01       87 阅读
  4. Python语言-面向对象

    2024-04-10 00:06:01       96 阅读

热门阅读

  1. Leetcode面试经典150_Q189轮转数组

    2024-04-10 00:06:01       35 阅读
  2. LeetCode|501. Find Mode in Binary Search Tree

    2024-04-10 00:06:01       26 阅读
  3. 爬虫之数据神器10---Peewee实现ORM的核心原理

    2024-04-10 00:06:01       30 阅读
  4. Day32 线程安全二

    2024-04-10 00:06:01       35 阅读
  5. Day31 线程安全一

    2024-04-10 00:06:01       24 阅读
  6. 2024.4.7力扣每日一题——王位继承顺序

    2024-04-10 00:06:01       39 阅读
  7. python--异常处理

    2024-04-10 00:06:01       42 阅读
  8. QB/T 4464-2013 家具用蜂窝板检测

    2024-04-10 00:06:01       36 阅读