【transformer理论+实战(二)】Lora本地微调实战 --deepseek-r1蒸馏模型

【Transformer理论+实战(三)】必要的 Pytorch 知识
【Transformer理论+实战(二)】Lora本地微调实战 --deepseek-r1蒸馏模型
【Transformer理论+实战(一)】Transformer & LLaMA & Lora介绍

一、准备工作

1.1 下载模型

Huggingface是一个开放的人工智能模型库,提供了大量经过预训练的模型供用户下载和使用。要下载模型访问Huggingface网站: https://huggingface.co/models

如果huggingface无法下载,可以使用下面的地址下载:

  • 模型下载地址:https://pan.quark.cn/s/a22f5a9e3490 (deepseek-r1-1.5b)
  • 数据集准备:https://pan.quark.cn/s/a220f415b35c

确保模型目录 deepseekr1-1.5b 下包含以下关键文件:

config.json
pytorch_model.bin  # 或 model.safetensors(必须存在至少一个)
tokenizer.json     # 或其他分词器文件(如 tokenizer_config.json)

1.2 依赖安装

# 在安装命令后添加 -i 参数指定镜像源:
pip install transformers datasets bitsandbytes -i https://mirrors.aliyun.com/pypi/simple/

# Transformers 库需要依赖 PyTorch、TensorFlow 或 Flax 中的一个才能加载模型
# 通用安装命令(CPU版)
pip install torch
# 如果有NVIDIA显卡(CUDA,如果下载包无cuXXX后缀表示是CPU版本)
pip install torch torchvision torchaudio --index-url https://mirrors.aliyun.com/pypi/simple/
# 直接复制whl文件的URL到迅雷中下载,可突破浏览器限速!对应版本:cu118代表cuda版本,cp313代表python3.13
pip install "torch-2.6.0+cu118-cp313-cp313-win_amd64.whl" -i https://pypi.tuna.tsinghua.edu.cn/simple

# 其他依赖(device_map="auto"、quantization_config)
pip install bitsandbytes accelerate>=0.26.0 --index-url https://mirrors.aliyun.com/pypi/simple/

ps:常用镜像源:

阿里云:https://mirrors.aliyun.com/pypi/simple/
豆瓣:  https://pypi.doubanio.com/simple/
华为云:https://repo.huaweicloud.com/repository/pypi/simple/

永久配置镜像源:

pip config set global.index-url  https://mirrors.aliyun.com/pypi/simple/
pip config list

查看 CUDA 版本(需提前安装 NVIDIA 驱动):

nvidia-smi  # 右上角显示最高支持的 CUDA 版本(如 12.6)

1.3 训练数据

data_prepare.py:

# -*- coding: utf-8 -*-
# here is list of 50 examples of prompt and completions focused on singing skills
samples = [
    {
   
        "prompt": "Question 1: What is the first step to improving your singing voice?",
        "completion": "Answer 1: Begin by warming up your vocal cords with gentle exercises like humming or lip trills."
    },
    {
   
        "prompt": "Question 2: How can you improve your breath control while singing?",
        "completion": "Answer 2: Practice diaphragmatic breathing by inhaling deeply through your nose and controlling your exhale while singing sustained notes."
    },
    {
   
        "prompt": "Question 3: What are common mistakes beginners make when learning to sing?",
        "completion": "Answer 3: Common mistakes include straining the voice, neglecting to warm up, and improper breathing techniques."
    },
    {
   
        "prompt": "Question 4: How do you find your vocal range?",
        "completion": "Answer 4: Experiment by singing scales up and down to identify the lowest and highest note you can comfortably sustain."
    },
    {
   
        "prompt": "Question 5: What exercises help improve pitch accuracy?",
        "completion": "Answer 5: Practice scales, use a piano or digital tuner for reference, and try interval training to enhance pitch precision."
    },
    {
   
        "prompt": "Question 6: How can you protect your vocal cords from strain?",
        "completion": "Answer 6: Avoid over-singing, stay hydrated, and limit exposure to irritants like smoke or excessively dry air."
    },
    {
   
        "prompt": "Question 7: What role does posture play in singing?",
        "completion": "Answer 7: Proper posture opens up the diaphragm and throat, allowing for better breath support and vocal projection."
    },
    {
   
        "prompt": "Question 8: How do you improve vocal tone quality?",
        "completion": "Answer 8: Focus on resonance and placement, and practice vocal exercises like sirens to achieve a smoother tone."
    },
    {
   
        "prompt": "Question 9: What techniques help develop vibrato in singing?",
        "completion": "Answer 9: Practice sustaining notes while gently oscillating your pitch; focus on relaxation and consistent airflow."
    },
    {
   
        "prompt": "Question 10: How can you overcome stage fright while singing?",
        "completion": "Answer 10: Prepare thoroughly, practice mindfulness techniques, and start performing in smaller, supportive settings."
    },
    {
   
        "prompt": "Question 11: What warm-up exercises are essential for singers?",
        "completion": "Answer 11: Lip trills, humming, and singing scales are effective warm-up exercises that prepare your voice for singing."
    },
    {
   
        "prompt": "Question 12: How do you sing high notes without straining?",
        "completion": "Answer 12: Use proper breath support, relax your throat, and place the sound forward in your mask (resonance areas)."
    },
    {
   
        "prompt": "Question 13: What is the importance of ear training for singers?",
        "completion": "Answer 13: Ear training helps singers recognize pitches, harmonies, and intervals, improving overall musicality and pitch accuracy."
    },
    {
   
        "prompt": "Question 14: How do you maintain vocal health during a busy singing schedule?",
        "completion": "Answer 14: Stay hydrated, get adequate rest, and avoid overuse by incorporating regular vocal breaks and proper warm-ups."
    },
    {
   
        "prompt": "Question 15: What foods and drinks should singers avoid?",
        "completion": "Answer 15: Avoid dairy, caffeine, and spicy foods before singing, as they can cause mucus buildup or throat irritation."
    },
    {
   
        "prompt": "Question 16: How can you improve diction while singing?",
        "completion": "Answer 16: Practice enunciation exercises like tongue twisters and focus on shaping vowels and consonants clearly."
    },
    {
   
        "prompt": "Question 17: What are the benefits of working with a vocal coach?",
        "completion": "Answer 17: A vocal coach provides personalized feedback, helps identify areas for improvement, and teaches proper technique."
    },
    {
   
        "prompt": "Question 18: How do you transition smoothly between vocal registers?",
        "completion": "Answer 18: Practice blending your chest and head voice through exercises like sirens and scales to achieve a seamless transition."
    },
    {
   
        "prompt": "Question 19: What is the purpose of singing scales during practice?",
        "completion": "Answer 19: Singing scales improves pitch accuracy, strengthens the voice, and helps with transitioning between notes smoothly."
    },
    {
   
        "prompt": "Question 20: How do you develop confidence in your singing voice?",
        "completion": "Answer 20: Record and listen to your progress, focus on your strengths, and perform regularly to build confidence over time."
    },
    {
   
        "prompt": "Question 21: What is falsetto, and how do you practice it?",
        "completion": "Answer 21: Falsetto is a light, airy register above the chest voice. Practice by relaxing your throat and gently accessing higher notes."
    },
    {
   
        "prompt": "Question 22: Why is hydration important for singers?",
        "completion": "Answer 22: Hydration keeps the vocal cords lubricated, preventing strain and allowing for smoother vocal production."
    },
    {
   
        "prompt": "Question 23: How do you project your voice without shouting?",
        "completion": "Answer 23: Use proper breath support, open your throat, and focus on forward resonance to amplify your sound naturally."
    },
    {
   
        "prompt": "Question 24: What techniques can improve vocal agility?",
        "completion": "Answer 24: Practice fast-paced scales, arpeggios, and runs while maintaining clarity and control over each note."
    },
    {
   
        "prompt": "Question 25: How do you develop a unique singing style?",
        "completion": "Answer 25: Experiment with phrasing, dynamics, and tone to find a style that reflects your personality and musical influences."
    },
    
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

造夢先森

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值