推理

term_id: inference

Category: engineering_practice

Definition

推理指的是部署阶段,在此阶段使用最终确定的模型对未见过的数据进行决策或预测。与更新权重的训练不同,推理消耗计算资源以产生结果。

Summary

训练好的模型处理新数据以生成预测或输出的阶段。

Key Concepts

  • 预测
  • 延迟
  • 吞吐量
  • 部署

Use Cases

  • 银行交易中的实时欺诈检测
  • 实时聊天交互中生成响应
  • 自动驾驶系统中的图像分类

Code Example

1
2
3
4
5
import torch
model.eval()
with torch.no_grad():
    output = model(input_tensor)
    prediction = torch.argmax(output, dim=1)