分类目录归档:None

LORA 微调 推理模型数据集合CoT 分布推理

示例1:

[
  {
    "instruction": "解决数学应用题",
    "input": "小明买了3支铅笔,每支2元;又买了5本笔记本,每本比铅笔贵4元。总花费多少?",
    "chain_of_thought": [
      "铅笔单价:2元/支 → 3支总价:3×2=6元",
      "笔记本单价:2+4=6元/本 → 5本总价:5×6=30元",
      "合计花费:6+30=36元"
    ],
    "output": "总花费为36元"
  }
]

示例2

[
  {
    "instruction": "分析医学问题",
    "input": "一名61岁的女性长期在咳嗽或打喷嚏等活动中不自觉地漏尿,但夜间没有漏尿,她接受了妇科检查和Q-tip测试。根据这些发现,膀胱测压最有可能揭示她的残余量和逼尿肌收缩情况?",
    "chain_of_thought": [
      "患者症状提示可能存在压力性尿失禁",
      "Q-tip测试用于评估尿道括约肌功能",
      "膀胱测压可以评估膀胱残余量和逼尿肌收缩力",
      "结合症状和检查结果,最可能的膀胱测压结果是残余量增加,逼尿肌收缩力减弱"
    ],
    "output": "膀胱测压最可能显示残余量增加,逼尿肌收缩力减弱"
  }
]

解析 JSON格式

instruction 指令 争对问题的信息

input 描述问题

chain_of_thought 思考列表,按照列表信息 一步 为一个值

output 输出结果

你可以通过在你的环境中使用 ollama 或任何其他部署框架部署 deepseek-r1 来生成自定义域相关数据集。但是,对于本教程,我们将使用 Magpie-Reasoning-V2 数据集,其中包含 DeepSeek-R1 生成的 250K 思路链 (CoT) 推理样本,这些示例涵盖了数学推理、编码和一般问题解决等各种任务。

http://www.hubwiz.com/blog/distill-deepseek-r1-into-your-model/

原文 http://www.hubwiz.com/blog/distill-deepseek-r1-into-your-model/

蒸馏数据集

蒸馏类型

有几种方法可以模拟蒸馏,每种方法都有自己的优点:

  1. 数据蒸馏
  • 在数据蒸馏中,教师模型生成合成数据或伪标签,然后用于训练学生模型。
  • 这种方法可以应用于广泛的任务,甚至是那些逻辑信息较少的任务(例如,开放式推理任务)。
  • Logits蒸馏
  • Logits 是应用 softmax 函数之前神经网络的原始输出分数。
  • 在logits 蒸馏中,学生模型被训练成匹配老师的logits,而不仅仅是最终的预测。
  • 这种方法保留了更多关于教师信心水平和决策过程的信息。
  • 特征蒸馏
  • 特征蒸馏涉及到将知识从教师模型的中间层传递给学生。
  • 通过对齐两个模型的隐表征,学生可以学习到更丰富、更抽象的特征。
{
 "instruction": "Solve for x: 2x + 5 = 15",
 "response": "<think>First, subtract 5 from both sides: 2x = 10. Then, divide by 2: x = 5.</think>"
}
from datasets import load_dataset

# Load the dataset
dataset = load_dataset("Magpie-Align/Magpie-Reasoning-V2-250K-CoT-Deepseek-R1-Llama-70B", token="YOUR_HF_TOKEN")
dataset = dataset["train"]

# Format the dataset
def format_instruction(example):
 return {
 "text": (
 "<|user|>\n"
 f"{example['instruction']}\n"
 "<|end|>\n"
 "<|assistant|>\n"
 f"{example['response']}\n"
 "<|end|>"
        )
    }

formatted_dataset = dataset.map(format_instruction, batched=False, remove_columns=subset_dataset.column_names)
formatted_dataset = formatted_dataset.train_test_split(test_size=0.1)  # 90-10 train-test split

ComfyUI知识补充 模型相关

1. 确定模型类型

首先,你需要确定你的需求,然后根据不同的需求下载不同的模型。

根据需求,常见的模型有以下几类:

  • Base 模型: 就是最常见的 AI 文生图模型,输入一段文字指令,AI 会根据你的指令生成图片。较常见的有 Stable Diffusion v1.5,Stable Diffusion XL 等。
  • LoRA 模型: 你可以简单将其理解为一种滤镜模型。通过它能生成更特殊的图片,比如在 Workflow 中加载线稿 LoRA 模型,就可以生成线稿风格的图片。甚至还有一些 LoRA 模型能让 AI 生成特定样貌的人物,比如一些名人的 LoRA,加载这种模型后,就可以生成特定的名人。但需要注意,这种模型没法脱离 Base 模型使用,这就意味着你需要先下载 Base 模型,然后再下载对应的 LoRA 模型才行。
  • Inpainting 模型: 如果你想要修改某张图片,比如去掉某个物体,或者修复某个物体,那么你就需要使用 Inpainting 模型。这种模型输入一张图片,然后输入一个遮罩,AI 会根据遮罩修复图片。这个模型可以单独使用。
  • Upscale 模型: 如果你想将一张图片放大,那么你就需要使用 Upscale 模型。这种模型输入一张图片,然后输入一个倍数,AI 会根据倍数放大图片。这个模型也可以单独使用。
  • ControlNet 模型: 如果你想控制图片中某个物体出现的位置,或者人物的站姿,那么你就需要使用 ControlNet 模型。但需要注意这个模型和 LoRA 类似,不能脱离 Base 模型使用。
  • 图生视频模型: 这种模型输入一段文字指令,AI 会根据你的指令将图片转为视频。

JS表格 其中有修改 和删除

快速表格生成:

function create_table_info(id, arr, arr_th) {
        $("#" + id).html("");
        var table = $("<table class='table'></table>");
        var trh = $("<tr></tr>");
        for (const element of arr_th) {
            var th = $("<th></th>");
            th.text(element);
            trh.append(th);
        }
        table.append(trh);
        console.log(arr);
        var l_i = 1;
        for (const element of arr) {
            var tr = $("<tr></tr>");
            var td = $("<td></td>");
            td.text(l_i);
            tr.append(td);
            l_i = l_i + 1;
            for (const key in element) {
                // console.log(element[key])
                if(typeof element[key]==="object"){
                    console.log(element[key]);
                }else{
                    var td = $("<td></td>");
                    td.text(element[key]);
                    tr.append(td);
                }

            }
            table.append(tr);
        }
        $("#" + id).append(table);
    }

加上删除 修改信息

function create_table(id, arr, arr_view, arr_th, del_url, edit_url, insert_url) {
            //必须包含ID 默认第一个为序号,其中设置了函数 pre_status
            var table = $("<table class='table'></table>");
            var trh = $("<tr></tr>");
            for (const element of arr_th) {
                var th = $("<th></th>");
                th.text(element);
                trh.append(th);
            }
            table.append(trh);
            var l_i = 1;
            for (const element of arr) {
                var tr = $("<tr></tr>");
                var td = $("<td></td>");
                td.text(l_i);
                tr.append(td);
                l_i = l_i + 1;
                if (arr_view.length < 1) {
                    for (const key in element) {
                        var td = $("<td></td>");
                        td.text(element[key]);
                        td.attr("data-id", element['id']);
                        td.attr("data-key", key);
                        td.attr("data-href", edit_url);
                        td.attr("class", "data-prompt");
                        tr.append(td);
                    }
                } else {
                    for (let i = 0; i < arr_view.length; i++) {
                        //此处需要你自己设置函数 pre_status
                        var key = arr_view[i];
                        if (key == "pre_status") {
                            var td = $("<td></td>");
                            var span = $("<span></span>");
                            if (element[key] > 0) {
                                span.addClass("label label-success data-btn");
                                span.attr("data-id", element['id']);
                                span.attr("data-href", edit_url);
                                span.attr("data-key", key);
                                span.attr("data-value", element[key]);
                                span.text("已经还款");
                            } else {
                                span.addClass("label label-danger data-btn");
                                span.attr("data-id", element['id']);
                                span.attr("data-href", edit_url);
                                span.attr("data-key", key);
                                span.attr("data-value", element[key]);
                                span.text("已经排款");
                            }
                            td.append(span);
                            tr.append(td);
                            //此处需要你自己设置函数
                        } else {
                            var td = $("<td></td>");
                            td.text(element[key]);
                            td.attr("data-id", element['id']);
                            td.attr("data-key", key);
                            td.attr("data-href", edit_url);
                            td.attr("class", "data-prompt");
                            tr.append(td);
                        }
                    }
                }
                fun_td = $("<td></td>");
                del_a = $("<a>删除</a>");
                del_a.attr("data-href", del_url)
                del_a.attr("data-id", element['id'])
                del_a.attr("class", "btn btn-danger del_a")
                fun_td.append(del_a)
                insert_a = $("<a class='insert_a'>插入</a>");
                insert_a.attr("data-href", insert_url)
                insert_a.attr("data-id", element['id'])
                tr.append(fun_td);
                table.append(tr);
            }
            $("#" + id).append(table);

            $(document).on("click", ".del_a", function (event) {
                var del_confirm = confirm("该操作会删除数据,请慎重操作!");
                var ths = $(this);
                if (del_confirm) {
                    ths.parent().addClass("bg-danger");
                    var url = $(this).attr('data-href');
                    var id = $(this).attr('data-id');
                    $.ajax({
                        url: url,
                        data: {
                            id: id
                        },
                        success: function (data) {
                            console.log(data);
                            //判断信息
                            if (data.status) {
                                ths.parent().parent().remove();

                            }
                        }

                    })
                }
            })
            $(document).on("click", ".data-btn", function (event) {

                var url = $(this).attr('data-href');
                var key = $(this).attr('data-key');
                var id = $(this).attr('data-id');
                var value = $(this).attr('data-value');
                var ths = $(this);
                if (value == 0) {
                    var btn_confirm = confirm("该操作会设置为已还款 OK ,请慎重操作!");
                    value = Date.now() / 1000;
                } else {
                    var btn_confirm = confirm("该操作会修改为已排款,请慎重操作!");
                    value = 0;
                }

                if (btn_confirm) {
                    ths.parent().addClass("bg-danger");
                    var url = $(this).attr('data-href');
                    var id = $(this).attr('data-id');
                    $.ajax({
                        url: url,
                        data: {
                            id: id,
                            key: key,
                            value: value
                        },
                        success: function (data) {
                            // console.log(data);
                            //判断信息
                            if (data.status) {
                                ths.parent().removeClass("bg-danger");
                                ths.parent().addClass("bg-success");
                                ths.attr('data-value', value);
                                if (value == 0) {
                                    ths.attr("class", "label label-danger data-btn")
                                    ths.text("已经排款");
                                } else {
                                    ths.attr("class", "label label-success data-btn")
                                    ths.text("已经还款");
                                }

                            }
                        }

                    })
                }
            })

            $(document).on("click", ".data-prompt", function (event) {
                var url = $(this).attr('data-href');
                var key = $(this).attr('data-key');
                var id = $(this).attr('data-id');
                $(this).addClass("bg-danger");
                var ths = $(this);
                var value = prompt("请输入修改的值:", $(this).text());//获得信息
                $.ajax({
                    url: url,
                    data: {
                        id: id,
                        key: key,
                        value: value
                    },
                    success: function (data) {
                        // console.log(data);
                        //判断信息 如果成功 就修改值
                        if (data.status) {
                            ths.removeClass("bg-danger");
                            ths.addClass("bg-success");
                            ths.html("<b>" + value + "</b>");
                        }
                    }

                })
            })
        }

调用

create_table("plan", data,arr_view=['hk_start','hk_date','hk_money','pre_status'], arr_th=["序号","开始日期","结束日期","金额","状态","操作"], del_url="{:url('portal/loan/ajax_hk_del')}", edit_url="{:url('portal/loan/ajax_hk_change')}", insert_url="ddddddd");
       

OLLAMA GPU运行及多卡运行

GPU运行

windows默认是CPU运行 需要修改 系统环境变量,添加一个:OLLAMA_GPU_LAYER 值设置为cuda

指定GPU运行(单卡)

还是系统环境变量 添加CUDA_VISIBLE_DEVICES 设置GPU的ID值 (UUID)可以通过nvidia-smi -L来查看显卡的UUID值。

多卡运行

还是系统环境变量修改OLLAMA服务配置 添加下面两个环境变量:

CUDA_VISIBLE_DEVICES设置值 0,1使用显卡(GPU)0和1

OLLAMA_SCHED_SPREAD设置值1启用负载均衡

P104驱动下载 360驱动大师 鲁大师 都可以

INMP441 micropython WAV

This code is for INMP441 to record the sound and save the sound in wav format

I’m using single LEFT channel MONO for my I2S microphone. Make adjustment for your implementation.

PIN CONFIGURATION:
SCK -> 4
WS -> 5
SD -> 18
LR -> 3 (You may also directly Ground the LR pin)

范例代码

from machine import Pin
from machine import I2S


#======= USER CONFIGURATION =======
RECORD_TIME_IN_SECONDS = 3
SAMPLE_RATE_IN_HZ = 16000
filename = 'mic.wav'
#======= USER CONFIGURATION =======

WAV_SAMPLE_SIZE_IN_BITS = 16
WAV_SAMPLE_SIZE_IN_BYTES = WAV_SAMPLE_SIZE_IN_BITS // 8
MIC_SAMPLE_BUFFER_SIZE_IN_BYTES = 4096
SDCARD_SAMPLE_BUFFER_SIZE_IN_BYTES = MIC_SAMPLE_BUFFER_SIZE_IN_BYTES // 2 # why divide by 2? only using 16-bits of 32-bit samples
NUM_SAMPLE_BYTES_TO_WRITE = int(RECORD_TIME_IN_SECONDS * SAMPLE_RATE_IN_HZ * WAV_SAMPLE_SIZE_IN_BYTES)
NUM_SAMPLES_IN_DMA_BUFFER = 256
NUM_CHANNELS = 1

#====== FUNCTIONS =========
def snip_16_mono(samples_in, samples_out):
    num_samples = len(samples_in) // 4
    for i in range(num_samples):
        samples_out[2*i] = samples_in[4*i + 2]
        samples_out[2*i + 1] = samples_in[4*i + 3]
            
    return num_samples * 2

def create_wav_header(sampleRate, bitsPerSample, num_channels, num_samples):
    datasize = int(num_samples * num_channels * bitsPerSample // 8)
    o = bytes("RIFF",'ascii')                                                   # (4byte) Marks file as RIFF
    o += (datasize + 36).to_bytes(4,'little')                                   # (4byte) File size in bytes excluding this and RIFF marker
    o += bytes("WAVE",'ascii')                                                  # (4byte) File type
    o += bytes("fmt ",'ascii')                                                  # (4byte) Format Chunk Marker
    o += (16).to_bytes(4,'little')                                              # (4byte) Length of above format data
    o += (1).to_bytes(2,'little')                                               # (2byte) Format type (1 - PCM)
    o += (num_channels).to_bytes(2,'little')                                    # (2byte)
    o += (sampleRate).to_bytes(4,'little')                                      # (4byte)
    o += (sampleRate * num_channels * bitsPerSample // 8).to_bytes(4,'little')  # (4byte)
    o += (num_channels * bitsPerSample // 8).to_bytes(2,'little')               # (2byte)
    o += (bitsPerSample).to_bytes(2,'little')                                   # (2byte)
    o += bytes("data",'ascii')                                                  # (4byte) Data Chunk Marker
    o += (datasize).to_bytes(4,'little')                                        # (4byte) Data size in bytes
    return o


################## MAIN #########################

#FOR ICS43434 only
PIN_I2S_LR = 3
Pin(PIN_I2S_LR, Pin.OUT, value=0)
###############
audio_in = I2S(1,
    sck=Pin(4), ws=Pin(5), sd=Pin(18),
    mode=I2S.RX,
    bits=32,
    format=I2S.MONO,
    rate=SAMPLE_RATE_IN_HZ,
    ibuf=20000,
               
)

wav = open(filename,'wb')

# create header for WAV file and write to SD card
wav_header = create_wav_header(
    SAMPLE_RATE_IN_HZ, 
    WAV_SAMPLE_SIZE_IN_BITS, 
    NUM_CHANNELS, 
    SAMPLE_RATE_IN_HZ * RECORD_TIME_IN_SECONDS
)
num_bytes_written = wav.write(wav_header)

# allocate sample arrays
#   memoryview used to reduce heap allocation in while loop
mic_samples = bytearray(MIC_SAMPLE_BUFFER_SIZE_IN_BYTES)
mic_samples_mv = memoryview(mic_samples)
wav_samples = bytearray(SDCARD_SAMPLE_BUFFER_SIZE_IN_BYTES)
wav_samples_mv = memoryview(wav_samples)

num_sample_bytes_written_to_wav = 0

print('Starting')
# read 32-bit samples from I2S microphone, snip upper 16-bits, write snipped samples to WAV file
while num_sample_bytes_written_to_wav < NUM_SAMPLE_BYTES_TO_WRITE:
        # try to read a block of samples from the I2S microphone
        # readinto() method returns 0 if no DMA buffer is full
        num_bytes_read_from_mic = audio_in.readinto(mic_samples_mv)
        if num_bytes_read_from_mic > 0:
            # snip upper 16-bits from each 32-bit microphone sample
            num_bytes_snipped = snip_16_mono(mic_samples_mv[:num_bytes_read_from_mic], wav_samples_mv)
            num_bytes_to_write = min(num_bytes_snipped, NUM_SAMPLE_BYTES_TO_WRITE - num_sample_bytes_written_to_wav)
            num_bytes_written = wav.write(wav_samples_mv[:num_bytes_to_write])
            num_sample_bytes_written_to_wav += num_bytes_written

wav.close()
audio_in.deinit()
print('Done')
print(f'{num_sample_bytes_written_to_wav} sample bytes written to WAV file')