当前位置:首页>python>纯 200行Python代码、零依赖的最小 GPT 实现,包含训练和推理的完整算法

纯 200行Python代码、零依赖的最小 GPT 实现,包含训练和推理的完整算法

  • 2026-07-02 01:29:21
纯 200行Python代码、零依赖的最小 GPT 实现,包含训练和推理的完整算法

microgpt.py 详细解析文档


一、实现技术

1.1 语言与依赖

技术项
说明
编程语言
Python 3(仅使用标准库)
外部依赖
 —— 不依赖 PyTorch、TensorFlow、NumPy 等任何第三方库
使用的标准库模块
os
(文件检查)、math(对数/指数运算)、random(随机数生成)、urllib.request(下载数据集)

1.2 核心技术栈

技术
实现方式
自动微分(Autograd)
手写 Value 类,通过计算图实现反向传播,支持标量级别的链式求导
Transformer 架构
基于 GPT-2 架构简化实现,包含多头自注意力(Multi-Head Self-Attention)和 MLP 前馈网络
优化器
从零实现 Adam 优化器,包含一阶动量 m、二阶动量 v 及偏差修正
分词器
字符级(Character-level)分词,每个唯一字符作为一个 token
正则化
使用 RMSNorm(Root Mean Square Layer Normalization)替代传统 LayerNorm
激活函数
使用 ReLU 替代原始 GPT-2 中的 GELU

二、架构设计

2.1 整体架构图

输入文本 (names)    │    ▼┌──────────────────────────────────────────────────────────┐│                    1. 数据准备                            ││  下载 names.txt → 清洗 → 随机打乱 → 字符级分词 → 构建词表  │└──────────────────────────────────────────────────────────┘    │    ▼┌──────────────────────────────────────────────────────────┐│                    2. 自动微分引擎 (Value 类)              ││  计算图节点 → 前向传播 → 拓扑排序 → 反向传播(链式求导)    │└──────────────────────────────────────────────────────────┘    │    ▼┌──────────────────────────────────────────────────────────┐│                    3. GPT 模型                            ││  Token Embedding + Position Embedding                    ││      → RMSNorm                                          ││      → [Multi-Head Attention + MLP] × n_layer            ││      → LM Head → Logits                                  │└──────────────────────────────────────────────────────────┘    │    ▼┌──────────────────────────────────────────────────────────┐│                    4. 训练循环                            ││  前向传播 → 交叉熵损失 → 反向传播 → Adam 更新 → 重复 N 步  │└──────────────────────────────────────────────────────────┘    │    ▼┌──────────────────────────────────────────────────────────┐│                    5. 推理生成                            ││  BOS → 自回归生成 → 温度采样 → 直到 BOS 或最大长度         │└──────────────────────────────────────────────────────────┘

2.2 自动微分引擎 —— Value 类

这是整个系统的数学基础。Value 类实现了一个标量级别的计算图引擎:

┌─────────────────────────────────────────┐│              Value 节点                  │├─────────────────────────────────────────┤│  data: float        # 当前节点的标量值    ││  grad: float        # 损失对该节点的梯度   ││  _children: tuple   # 子节点(前驱节点)   ││  _local_grads: tuple # 局部偏导数         │├─────────────────────────────────────────┤│  __add__ / __mul__  # 运算重载,构建计算图 ││  backward()         # 拓扑排序 + 反向传播  │└─────────────────────────────────────────┘

关键设计决策:

  • 使用 __slots__ 减少内存开销(Python 层面优化)
  • 每个运算创建新的 Value 节点,同时记录局部梯度
  • backward()
     采用拓扑排序确保梯度按正确顺序传播
  • 支持的操作:+-*/**logexprelu

局部梯度规则(链式法则基础):

运算
局部梯度
c = a + b
∂c/∂a = 1, ∂c/∂b = 1
c = a * b
∂c/∂a = b.data, ∂c/∂b = a.data
c = a ** n
∂c/∂a = n * a^(n-1)
c = log(a)
∂c/∂a = 1/a
c = exp(a)
∂c/∂a = exp(a)
c = relu(a)
∂c/∂a = 1 if a > 0 else 0

2.3 GPT 模型架构

模型参数配置(可调整 n_layer / n_embd / block_size / n_head 来缩放):

参数
默认值
说明
n_layer
1
Transformer 层数
n_embd
16
嵌入维度(网络宽度)
block_size
16
最大上下文长度(最长名字为 15 字符)
n_head
4
注意力头数
head_dim
4
每头的维度 (= n_embd / n_head)

参数量: 约 6,000+ 个标量参数(字符级,500 步训练即可收敛)

模型参数矩阵一览:

参数名
形状
说明
wte
(vocab_size, n_embd)
Token 嵌入矩阵
wpe
(block_size, n_embd)
位置嵌入矩阵
layer{i}.attn_wq
(n_embd, n_embd)
第 i 层的 Query 投影
layer{i}.attn_wk
(n_embd, n_embd)
第 i 层的 Key 投影
layer{i}.attn_wv
(n_embd, n_embd)
第 i 层的 Value 投影
layer{i}.attn_wo
(n_embd, n_embd)
第 i 层的输出投影
layer{i}.mlp_fc1
(4*n_embd, n_embd)
MLP 第一层(扩展 4 倍)
layer{i}.mlp_fc2
(n_embd, 4*n_embd)
MLP 第二层(压缩回原维度)
lm_head
(vocab_size, n_embd)
语言模型头(输出 logits)

单层 Transformer Block 正向传播流程:

输入 x (残差流)    │    ├──→ RMSNorm → [Multi-Head Attention] → + → 残差连接    │                                              │    └──→ RMSNorm → [MLP: Linear→ReLU→Linear] → + ──┘                                                    │                                                输出 x
  1. RMSNorm
    :计算均方根作为缩放因子,对输入进行归一化
  2. Multi-Head Self-Attention
    • 通过可学习的 Q/K/V 投影生成查询、键、值
    • 将 Q/K/V 按头数切分(head_dim 维度)
    • 计算缩放点积注意力:softmax(Q·K^T / √d_k) · V
    • 拼接各头输出并通过 attn_wo 投影
  3. MLP
    :两层线性变换 + ReLU 激活,先扩展 4 倍再压缩
  4. 残差连接
    :每个子层后加上原始输入,缓解梯度消失

2.4 Adam 优化器

从零实现,完整包含以下组件:

组件
公式
说明
一阶动量 m
m_t = β₁·m_{t-1} + (1-β₁)·g_t
梯度的指数移动平均
二阶动量 v
v_t = β₂·v_{t-1} + (1-β₂)·g_t²
梯度平方的指数移动平均
偏差修正 m̂
m̂ = m_t / (1-β₁^t)
修正初始阶段的偏差
偏差修正 v̂
v̂ = v_t / (1-β₂^t)
修正初始阶段的偏差
参数更新
θ -= lr · m̂ / (√v̂ + ε)
自适应学习率更新

超参数:lr=0.01β₁=0.85β₂=0.99ε=1e-8

学习率采用线性衰减策略:lr_t = lr · (1 - step / num_steps)


三、执行流程

3.1 训练流程

┌─────────────────────────────────────────────────────────────────┐│  Step 0: 数据准备                                                ││  ├── 检查 input.txt 是否存在,不存在则从 GitHub 下载 names.txt    ││  ├── 读取所有名字,清洗空行,随机打乱                              ││  └── 构建字符级词表:去重字符 + BOS 特殊标记                       │├─────────────────────────────────────────────────────────────────┤│  Step 1: 参数初始化                                              ││  ├── 定义模型超参数 (n_layer, n_embd, block_size, n_head)         ││  ├── 用 N(00.08) 初始化所有权重矩阵                             ││  └── 展平所有参数为单个列表 params                                 │├─────────────────────────────────────────────────────────────────┤│  Step 2: 训练循环 (num_steps=1000)                                ││  for step in 0..999:                                            ││    ├── 2a. 取一个文档,转为 token 序列 [BOS, t1, t2, ..., BOS]   ││    ├── 2b. 前向传播:逐个 token 输入 GPT,构建完整计算图            ││    │       ├── Token Embedding + Position Embedding → x           ││    │       ├── 对每个 Transformer 层:                             ││    │       │   ├── RMSNorm(x)                                     ││    │       │   ├── Multi-Head Attention (Q, K, V)                 ││    │       │   ├── 残差连接 x = attn_out + residual               ││    │       │   ├── RMSNorm(x)                                     ││    │       │   ├── MLP: Linear → ReLU → Linear                    ││    │       │   └── 残差连接 x = mlp_out + residual                ││    │       └── LM Head: Linear → logits                           ││    ├── 2c. Softmax + 负对数似然 → 交叉熵损失                       ││    ├── 2d. loss.backward(): 拓扑排序 + 反向传播梯度                ││    ├── 2e. Adam 更新所有参数,清零梯度                              ││    └── 2f. 打印当前步数和损失                                      │├─────────────────────────────────────────────────────────────────┤│  Step 3: 推理生成                                                ││  ├── 从 BOS 开始,自回归生成                                       ││  ├── 每步通过 GPT 得到 logits → /temperature → softmax → 采样     ││  ├── 遇到 BOS 或达到 block_size 时停止                             ││  └── 生成 20 个样本名字并打印                                      │└─────────────────────────────────────────────────────────────────┘

3.2 关键流程详解

3.2.1 前向传播 — 自回归训练

训练使用 Teacher Forcing 策略:给定位置 pos_id 的 token,预测位置 pos_id+1 的 token。每个位置的注意力只能看到当前及之前的 token(因果注意力,通过 KV 缓存实现)。

# 对序列中的每个位置并行(实际是串行但缓存了 K/V):for pos_id in range(n):    token_id, target_id = tokens[pos_id], tokens[pos_id + 1]  # 输入和目标错位一位    logits = gpt(token_id, pos_id, keysvalues)               # 前向传播    probs = softmax(logits)                                     # 转为概率    loss_t = -probs[target_id].log()                            # 交叉熵(单 token)

3.2.2 反向传播 — 自动微分

loss.backward() 执行流程:    1. 从 loss 节点出发,DFS 遍历计算图,收集所有节点    2. 拓扑排序:确保子节点排在前面    3. 反向遍历(从 loss 到输入):       for each node:           for each (child, local_grad) in node:               child.grad += local_grad * node.grad  # 链式法则

3.2.3 推理 — 温度采样

probs = softmax([l / temperature for l in logits])  # temperature ∈ (0, 1]token_id = random.choices(range(vocab_size), weights=probs)[0]
  • 适中的创造性,使生成的名字既多样又合理
  • 温度越低 → 概率分布越尖锐 → 生成越确定性
  • 温度越高 → 概率分布越平滑 → 生成越随机

四、总结

4.1 代码特性

特性
说明
代码行数
约 200 行(含注释和空行)
依赖
零外部依赖,纯 Python 标准库
完整性
包含数据加载、分词、模型定义、训练、推理全流程
可读性
代码组织清晰,注释风格独特("Let there be...")
计算图
动态构建,每步训练都从头构建完整计算图

4.2 设计亮点

  1. 极简主义
    :每个组件都压缩到最简形式,例如 linear() 函数仅用一行列表推导实现矩阵乘法
  2. 自包含
    :不依赖任何深度学习框架,完整展示了深度学习的所有核心概念
  3. 可扩展
    :只需调整 n_layern_embd 等超参数即可缩放模型规模
  4. KV 缓存
    :训练时手动维护 keys/values 列表实现因果注意力,也是推理加速的典范
  5. RMSNorm 设计
    :归一化放在残差连接之前(Pre-Norm),这是当代大模型的标准做法

4.3 局限性

局限
说明
性能
纯 Python 标量运算,极度缓慢(无法用于实际训练)
规模
字符级分词,仅适用于短文本(如名字生成)
内存
计算图无释放机制,长序列训练会累积大量节点
功能
不支持批处理、GPU 加速、dropout 等现代训练技术
精度
标量级自动微分,不具备向量化计算能力

五、思考与启示

5.1 教育价值

microgpt.py 是一份极其珍贵的教学代码。它用不到 200 行纯 Python,将以下概念一次性讲透:

  • 自动微分原理
    :通过手写 Value 类和 backward() 方法,让学习者直观理解 PyTorch/TensorFlow 的底层机制
  • Transformer 架构
    :剥离了工程优化后,Transformer 核心就是注意力计算 + MLP + 残差连接 + 归一化,并不神秘
  • 优化器内部机制
    :Adam 的动量、偏差修正等概念通过几十行代码变得触手可及
  • 端到端训练
    :从零开始看到一个模型如何从随机初始化到生成有意义输出

5.2 架构洞察

  1. "Everything else is just efficiency":文件头部的这句注释是全文的灵魂。PyTorch 所做的——GPU 加速、向量化、算子融合、并行训练——本质上都是在优化这段 200 行代码的速度和规模。

  2. 计算图与神经网络的关系:神经网络的前向传播本质是构建一个巨大的有向无环计算图,反向传播是对该图执行链式法则。Value 类的 40 行代码完美诠释了这一本质。

  3. RMSNorm vs LayerNorm:代码选择了 RMSNorm(仅用均方根缩放,不减去均值),这是 LLaMA 等现代大模型的做法——更简单、更高效、效果相当。

  4. Pre-Norm 策略:归一化放在子层之前而非之后,这是当代 Transformer 的标准配置,能有效稳定深层网络的训练。

  5. 参数的数学结构:所有参数都存储为 Value 对象的二维列表,state_dict 的命名规范与 PyTorch 一致,暗示了工业界实践的影子。

5.3 实践建议

对于希望深入理解 GPT 的开发者:

  1. 先读懂这段代码
    :在接触 PyTorch 版 GPT 实现之前,先彻底理解 microgpt.py,建立对自动微分和 Transformer 的直觉
  2. 动手修改实验
    • 增大 n_layer 观察深层网络的训练行为
    • 替换 ReLU 为 GELU 比较效果差异
    • 添加 dropout 防止过拟合
    • 改用 BPE 分词替代字符级分词
  3. 性能剖析
    :在 backward() 中添加计数器,直观感受计算图的规模增长
  4. 作为模板
    :这段代码的结构是任何深度学习项目的标准模板——数据 → 模型 → 损失 → 优化器 → 循环

5.4 与工业界 GPT 的对比

维度
microgpt.py
GPT-3 / GPT-4
代码量
~200 行
数十万行(含工程代码)
参数规模
~6,000
175B ~ 1.8T
分词
字符级(~27 token)
BPE(50K+ token)
训练数据
几千个人名
数万亿 token
训练框架
纯 Python
PyTorch + Megatron + 分布式
硬件
CPU 单核
数千/数万 GPU
推理速度
毫秒/字符
毫秒/千 token

尽管差距悬殊,两者的核心数学原理完全一致——这正是 microgpt.py 的魅力所在。


附录:关键函数速查

函数/类
行号
作用
Value.__init__
33-37
计算图节点初始化
Value.backward
59-72
自动微分反向传播
matrix
80
用高斯分布初始化权重矩阵
linear
94-95
线性变换(矩阵乘法)
softmax
97-101
Softmax 归一化
rmsnorm
103-106
RMS 归一化
gpt
108-144
GPT 模型前向传播(核心)
Adam 更新
174-182
优化器参数更新

源码
"""The most atomic way to train and run inference for a GPT in pure, dependency-free Python.This file is the complete algorithm.Everything else is just efficiency.@karpathy"""import os       # os.path.existsimport math     # math.log, math.expimport random   # random.seed, random.choices, random.gauss, random.shufflerandom.seed(42# Let there be order among chaos# Let there be a Dataset `docs`: list[str] of documents (e.g. a list of names)if not os.path.exists('input.txt'):    import urllib.request    names_url = 'https://raw.githubusercontent.com/karpathy/makemore/988aa59/names.txt'    urllib.request.urlretrieve(names_url, 'input.txt')docs = [line.strip() for line in open('input.txt'if line.strip()]random.shuffle(docs)print(f"num docs: {len(docs)}")# Let there be a Tokenizer to translate strings to sequences of integers ("tokens") and backuchars = sorted(set(''.join(docs))) # unique characters in the dataset become token ids 0..n-1BOS = len(uchars) # token id for a special Beginning of Sequence (BOS) tokenvocab_size = len(uchars) + 1 # total number of unique tokens, +1 is for BOSprint(f"vocab size: {vocab_size}")# Let there be Autograd to recursively apply the chain rule through a computation graphclass Value:    __slots__ = ('data''grad''_children''_local_grads'# Python optimization for memory usage    def __init__(self, data, children=(), local_grads=()):        self.data = data                # scalar value of this node calculated during forward pass        self.grad = 0                   # derivative of the loss w.r.t. this node, calculated in backward pass        self._children = children       # children of this node in the computation graph        self._local_grads = local_grads # local derivative of this node w.r.t. its children    def __add__(self, other):        other = other if isinstance(other, Value) else Value(other)        return Value(self.data + other.data, (self, other), (11))    def __mul__(self, other):        other = other if isinstance(other, Value) else Value(other)        return Value(self.data * other.data, (self, other), (other.data, self.data))    def __pow__(self, other): return Value(self.data**other, (self,), (other * self.data**(other-1),))    def log(self): return Value(math.log(self.data), (self,), (1/self.data,))    def exp(self): return Value(math.exp(self.data), (self,), (math.exp(self.data),))    def relu(self): return Value(max(0self.data), (self,), (float(self.data > 0),))    def __neg__(self): return self * -1    def __radd__(self, other): return self + other    def __sub__(self, other): return self + (-other)    def __rsub__(self, other): return other + (-self)    def __rmul__(self, other): return self * other    def __truediv__(self, other): return self * other**-1    def __rtruediv__(self, other): return other * self**-1    def backward(self):        topo = []        visited = set()        def build_topo(v):            if v not in visited:                visited.add(v)                for child in v._children:                    build_topo(child)                topo.append(v)        build_topo(self)        self.grad = 1        for v in reversed(topo):            for child, local_grad in zip(v._children, v._local_grads):                child.grad += local_grad * v.grad# Initialize the parameters, to store the knowledge of the modeln_layer = 1     # depth of the transformer neural network (number of layers)n_embd = 16     # width of the network (embedding dimension)block_size = 16 # maximum context length of the attention window (note: the longest name is 15 characters)n_head = 4      # number of attention headshead_dim = n_embd // n_head # derived dimension of each headmatrix = lambda nout, nin, std=0.08: [[Value(random.gauss(0, std)) for _ in range(nin)] for _ in range(nout)]state_dict = {'wte': matrix(vocab_size, n_embd), 'wpe': matrix(block_size, n_embd), 'lm_head': matrix(vocab_size, n_embd)}for i in range(n_layer):    state_dict[f'layer{i}.attn_wq'] = matrix(n_embd, n_embd)    state_dict[f'layer{i}.attn_wk'] = matrix(n_embd, n_embd)    state_dict[f'layer{i}.attn_wv'] = matrix(n_embd, n_embd)    state_dict[f'layer{i}.attn_wo'] = matrix(n_embd, n_embd)    state_dict[f'layer{i}.mlp_fc1'] = matrix(4 * n_embd, n_embd)    state_dict[f'layer{i}.mlp_fc2'] = matrix(n_embd, 4 * n_embd)params = [p for mat in state_dict.values() for row in mat for p in row] # flatten params into a single list[Value]print(f"num params: {len(params)}")# Define the model architecture: a function mapping tokens and parameters to logits over what comes next# Follow GPT-2, blessed among the GPTs, with minor differences: layernorm -> rmsnorm, no biases, GeLU -> ReLUdef linear(x, w):    return [sum(wi * xi for wi, xi in zip(wo, x)) for wo in w]def softmax(logits):    max_val = max(val.data for val in logits)    exps = [(val - max_val).exp() for val in logits]    total = sum(exps)    return [e / total for e in exps]def rmsnorm(x):    ms = sum(xi * xi for xi in x) / len(x)    scale = (ms + 1e-5) ** -0.5    return [xi * scale for xi in x]def gpt(token_id, pos_id, keys, values):    tok_emb = state_dict['wte'][token_id] # token embedding    pos_emb = state_dict['wpe'][pos_id] # position embedding    x = [t + p for t, p in zip(tok_emb, pos_emb)] # joint token and position embedding    x = rmsnorm(x) # note: not redundant due to backward pass via the residual connection    for li in range(n_layer):        # 1) Multi-head Attention block        x_residual = x        x = rmsnorm(x)        q = linear(x, state_dict[f'layer{li}.attn_wq'])        k = linear(x, state_dict[f'layer{li}.attn_wk'])        v = linear(x, state_dict[f'layer{li}.attn_wv'])        keys[li].append(k)        values[li].append(v)        x_attn = []        for h in range(n_head):            hs = h * head_dim            q_h = q[hs:hs+head_dim]            k_h = [ki[hs:hs+head_dim] for ki in keys[li]]            v_h = [vi[hs:hs+head_dim] for vi in values[li]]            attn_logits = [sum(q_h[j] * k_h[t][j] for j in range(head_dim)) / head_dim**0.5 for t in range(len(k_h))]            attn_weights = softmax(attn_logits)            head_out = [sum(attn_weights[t] * v_h[t][j] for t in range(len(v_h))) for j in range(head_dim)]            x_attn.extend(head_out)        x = linear(x_attn, state_dict[f'layer{li}.attn_wo'])        x = [a + b for a, b in zip(x, x_residual)]        # 2) MLP block        x_residual = x        x = rmsnorm(x)        x = linear(x, state_dict[f'layer{li}.mlp_fc1'])        x = [xi.relu() for xi in x]        x = linear(x, state_dict[f'layer{li}.mlp_fc2'])        x = [a + b for a, b in zip(x, x_residual)]    logits = linear(x, state_dict['lm_head'])    return logits# Let there be Adam, the blessed optimizer and its bufferslearning_rate, beta1, beta2, eps_adam = 0.010.850.991e-8m = [0.0] * len(params) # first moment bufferv = [0.0] * len(params) # second moment buffer# Repeat in sequencenum_steps = 1000 # number of training stepsfor step in range(num_steps):    # Take single document, tokenize it, surround it with BOS special token on both sides    doc = docs[step % len(docs)]    tokens = [BOS] + [uchars.index(ch) for ch in doc] + [BOS]    n = min(block_size, len(tokens) - 1)    # Forward the token sequence through the model, building up the computation graph all the way to the loss    keys, values = [[] for _ in range(n_layer)], [[] for _ in range(n_layer)]    losses = []    for pos_id in range(n):        token_id, target_id = tokens[pos_id], tokens[pos_id + 1]        logits = gpt(token_id, pos_id, keys, values)        probs = softmax(logits)        loss_t = -probs[target_id].log()        losses.append(loss_t)    loss = (1 / n) * sum(losses) # final average loss over the document sequence. May yours be low.    # Backward the loss, calculating the gradients with respect to all model parameters    loss.backward()    # Adam optimizer update: update the model parameters based on the corresponding gradients    lr_t = learning_rate * (1 - step / num_steps) # linear learning rate decay    for i, p in enumerate(params):        m[i] = beta1 * m[i] + (1 - beta1) * p.grad        v[i] = beta2 * v[i] + (1 - beta2) * p.grad ** 2        m_hat = m[i] / (1 - beta1 ** (step + 1))        v_hat = v[i] / (1 - beta2 ** (step + 1))        p.data -= lr_t * m_hat / (v_hat ** 0.5 + eps_adam)        p.grad = 0    print(f"step {step+1:4d} / {num_steps:4d} | loss {loss.data:.4f}", end='\r')# Inference: may the model babble back to ustemperature = 0.5 # in (0, 1], control the "creativity" of generated text, low to highprint("\n--- inference (new, hallucinated names) ---")for sample_idx in range(20):    keys, values = [[] for _ in range(n_layer)], [[] for _ in range(n_layer)]    token_id = BOS    sample = []    for pos_id in range(block_size):        logits = gpt(token_id, pos_id, keys, values)        probs = softmax([l / temperature for l in logits])        token_id = random.choices(range(vocab_size), weights=[p.data for p in probs])[0]        if token_id == BOS:            break        sample.append(uchars[token_id])    print(f"sample {sample_idx+1:2d}{''.join(sample)}")

👋 我是布道者,在「Bit艺术」专注做一件事:用古典智慧与AI工具,解构现代人的成长与效率难题。

立即行动,获取更多:

  1. 点击右上角「···」→ 设为星标🌟
    ,不错过任何一篇深度剖析。

关注我,持续收获职场进阶硬核知识。

期待你在留言区分享你的团队管理困境或成功经验,每一条我都会认真阅读。


#曾国藩 #研发管理 #团队管理 #领导力 #职场进阶

最新文章

随机文章

基本 文件 流程 错误 SQL 调试
  1. 请求信息 : 2026-07-04 03:48:16 HTTP/2.0 GET : https://f.mffb.com.cn/a/492001.html
  2. 运行时间 : 0.089676s [ 吞吐率:11.15req/s ] 内存消耗:4,672.88kb 文件加载:140
  3. 缓存信息 : 0 reads,0 writes
  4. 会话信息 : SESSION_ID=cca1ee4e3a17b2e4a315e76b594ad506
  1. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/public/index.php ( 0.79 KB )
  2. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/autoload.php ( 0.17 KB )
  3. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/composer/autoload_real.php ( 2.49 KB )
  4. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/composer/platform_check.php ( 0.90 KB )
  5. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/composer/ClassLoader.php ( 14.03 KB )
  6. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/composer/autoload_static.php ( 4.90 KB )
  7. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-helper/src/helper.php ( 8.34 KB )
  8. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-validate/src/helper.php ( 2.19 KB )
  9. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/helper.php ( 1.47 KB )
  10. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/stubs/load_stubs.php ( 0.16 KB )
  11. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Exception.php ( 1.69 KB )
  12. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-container/src/Facade.php ( 2.71 KB )
  13. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/symfony/deprecation-contracts/function.php ( 0.99 KB )
  14. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/symfony/polyfill-mbstring/bootstrap.php ( 8.26 KB )
  15. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/symfony/polyfill-mbstring/bootstrap80.php ( 9.78 KB )
  16. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/symfony/var-dumper/Resources/functions/dump.php ( 1.49 KB )
  17. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-dumper/src/helper.php ( 0.18 KB )
  18. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/symfony/var-dumper/VarDumper.php ( 4.30 KB )
  19. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/App.php ( 15.30 KB )
  20. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-container/src/Container.php ( 15.76 KB )
  21. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/psr/container/src/ContainerInterface.php ( 1.02 KB )
  22. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/provider.php ( 0.19 KB )
  23. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Http.php ( 6.04 KB )
  24. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-helper/src/helper/Str.php ( 7.29 KB )
  25. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Env.php ( 4.68 KB )
  26. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/common.php ( 0.03 KB )
  27. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/helper.php ( 18.78 KB )
  28. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Config.php ( 5.54 KB )
  29. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/app.php ( 0.95 KB )
  30. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/cache.php ( 0.78 KB )
  31. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/console.php ( 0.23 KB )
  32. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/cookie.php ( 0.56 KB )
  33. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/database.php ( 2.48 KB )
  34. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/facade/Env.php ( 1.67 KB )
  35. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/filesystem.php ( 0.61 KB )
  36. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/lang.php ( 0.91 KB )
  37. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/log.php ( 1.35 KB )
  38. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/middleware.php ( 0.19 KB )
  39. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/route.php ( 1.89 KB )
  40. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/session.php ( 0.57 KB )
  41. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/trace.php ( 0.34 KB )
  42. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/view.php ( 0.82 KB )
  43. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/event.php ( 0.25 KB )
  44. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Event.php ( 7.67 KB )
  45. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/service.php ( 0.13 KB )
  46. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/AppService.php ( 0.26 KB )
  47. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Service.php ( 1.64 KB )
  48. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Lang.php ( 7.35 KB )
  49. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/lang/zh-cn.php ( 13.70 KB )
  50. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/initializer/Error.php ( 3.31 KB )
  51. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/initializer/RegisterService.php ( 1.33 KB )
  52. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/services.php ( 0.14 KB )
  53. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/service/PaginatorService.php ( 1.52 KB )
  54. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/service/ValidateService.php ( 0.99 KB )
  55. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/service/ModelService.php ( 2.04 KB )
  56. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-trace/src/Service.php ( 0.77 KB )
  57. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Middleware.php ( 6.72 KB )
  58. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/initializer/BootService.php ( 0.77 KB )
  59. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/Paginator.php ( 11.86 KB )
  60. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-validate/src/Validate.php ( 63.20 KB )
  61. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/Model.php ( 23.55 KB )
  62. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/concern/Attribute.php ( 21.05 KB )
  63. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/concern/AutoWriteData.php ( 4.21 KB )
  64. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/concern/Conversion.php ( 6.44 KB )
  65. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/concern/DbConnect.php ( 5.16 KB )
  66. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/concern/ModelEvent.php ( 2.33 KB )
  67. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/concern/RelationShip.php ( 28.29 KB )
  68. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-helper/src/contract/Arrayable.php ( 0.09 KB )
  69. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-helper/src/contract/Jsonable.php ( 0.13 KB )
  70. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/contract/Modelable.php ( 0.09 KB )
  71. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Db.php ( 2.88 KB )
  72. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/DbManager.php ( 8.52 KB )
  73. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Log.php ( 6.28 KB )
  74. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Manager.php ( 3.92 KB )
  75. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/psr/log/src/LoggerTrait.php ( 2.69 KB )
  76. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/psr/log/src/LoggerInterface.php ( 2.71 KB )
  77. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Cache.php ( 4.92 KB )
  78. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/psr/simple-cache/src/CacheInterface.php ( 4.71 KB )
  79. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-helper/src/helper/Arr.php ( 16.63 KB )
  80. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/cache/driver/File.php ( 7.84 KB )
  81. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/cache/Driver.php ( 9.03 KB )
  82. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/contract/CacheHandlerInterface.php ( 1.99 KB )
  83. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/Request.php ( 0.09 KB )
  84. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Request.php ( 55.78 KB )
  85. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/middleware.php ( 0.25 KB )
  86. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Pipeline.php ( 2.61 KB )
  87. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-trace/src/TraceDebug.php ( 3.40 KB )
  88. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/middleware/SessionInit.php ( 1.94 KB )
  89. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Session.php ( 1.80 KB )
  90. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/session/driver/File.php ( 6.27 KB )
  91. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/contract/SessionHandlerInterface.php ( 0.87 KB )
  92. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/session/Store.php ( 7.12 KB )
  93. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Route.php ( 23.73 KB )
  94. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/RuleName.php ( 5.75 KB )
  95. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/Domain.php ( 2.53 KB )
  96. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/RuleGroup.php ( 22.43 KB )
  97. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/Rule.php ( 26.95 KB )
  98. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/RuleItem.php ( 9.78 KB )
  99. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/route/app.php ( 1.72 KB )
  100. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/facade/Route.php ( 4.70 KB )
  101. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/dispatch/Controller.php ( 4.74 KB )
  102. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/Dispatch.php ( 10.44 KB )
  103. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/controller/Index.php ( 4.81 KB )
  104. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/BaseController.php ( 2.05 KB )
  105. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/facade/Db.php ( 0.93 KB )
  106. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/connector/Mysql.php ( 5.44 KB )
  107. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/PDOConnection.php ( 52.47 KB )
  108. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/Connection.php ( 8.39 KB )
  109. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/ConnectionInterface.php ( 4.57 KB )
  110. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/builder/Mysql.php ( 16.58 KB )
  111. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/Builder.php ( 24.06 KB )
  112. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/BaseBuilder.php ( 27.50 KB )
  113. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/Query.php ( 15.71 KB )
  114. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/BaseQuery.php ( 45.13 KB )
  115. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/TimeFieldQuery.php ( 7.43 KB )
  116. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/AggregateQuery.php ( 3.26 KB )
  117. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/ModelRelationQuery.php ( 20.07 KB )
  118. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/ParamsBind.php ( 3.66 KB )
  119. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/ResultOperation.php ( 7.01 KB )
  120. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/WhereQuery.php ( 19.37 KB )
  121. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/JoinAndViewQuery.php ( 7.11 KB )
  122. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/TableFieldInfo.php ( 2.63 KB )
  123. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/Transaction.php ( 2.77 KB )
  124. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/log/driver/File.php ( 5.96 KB )
  125. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/contract/LogHandlerInterface.php ( 0.86 KB )
  126. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/log/Channel.php ( 3.89 KB )
  127. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/event/LogRecord.php ( 1.02 KB )
  128. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-helper/src/Collection.php ( 16.47 KB )
  129. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/facade/View.php ( 1.70 KB )
  130. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/View.php ( 4.39 KB )
  131. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Response.php ( 8.81 KB )
  132. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/response/View.php ( 3.29 KB )
  133. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Cookie.php ( 6.06 KB )
  134. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-view/src/Think.php ( 8.38 KB )
  135. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/contract/TemplateHandlerInterface.php ( 1.60 KB )
  136. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-template/src/Template.php ( 46.61 KB )
  137. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-template/src/template/driver/File.php ( 2.41 KB )
  138. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-template/src/template/contract/DriverInterface.php ( 0.86 KB )
  139. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/runtime/temp/067d451b9a0c665040f3f1bdd3293d68.php ( 11.98 KB )
  140. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-trace/src/Html.php ( 4.42 KB )
  1. CONNECT:[ UseTime:0.000659s ] mysql:host=127.0.0.1;port=3306;dbname=f_mffb;charset=utf8mb4
  2. SHOW FULL COLUMNS FROM `fenlei` [ RunTime:0.000681s ]
  3. SELECT * FROM `fenlei` WHERE `fid` = 0 [ RunTime:0.000258s ]
  4. SELECT * FROM `fenlei` WHERE `fid` = 63 [ RunTime:0.000277s ]
  5. SHOW FULL COLUMNS FROM `set` [ RunTime:0.000481s ]
  6. SELECT * FROM `set` [ RunTime:0.000200s ]
  7. SHOW FULL COLUMNS FROM `article` [ RunTime:0.000556s ]
  8. SELECT * FROM `article` WHERE `id` = 492001 LIMIT 1 [ RunTime:0.005634s ]
  9. UPDATE `article` SET `lasttime` = 1783108096 WHERE `id` = 492001 [ RunTime:0.005411s ]
  10. SELECT * FROM `fenlei` WHERE `id` = 66 LIMIT 1 [ RunTime:0.000302s ]
  11. SELECT * FROM `article` WHERE `id` < 492001 ORDER BY `id` DESC LIMIT 1 [ RunTime:0.000419s ]
  12. SELECT * FROM `article` WHERE `id` > 492001 ORDER BY `id` ASC LIMIT 1 [ RunTime:0.000351s ]
  13. SELECT * FROM `article` WHERE `id` < 492001 ORDER BY `id` DESC LIMIT 10 [ RunTime:0.001165s ]
  14. SELECT * FROM `article` WHERE `id` < 492001 ORDER BY `id` DESC LIMIT 10,10 [ RunTime:0.001005s ]
  15. SELECT * FROM `article` WHERE `id` < 492001 ORDER BY `id` DESC LIMIT 20,10 [ RunTime:0.006426s ]
0.091229s