ChatGPT 快速入门

GPT

由 OpenAI 训练的大型语言模型,也称为 Generative Pretrained Transformer。

版本 发布时间 模型参数 GPU内存 能力
GPT 2018年 1.17亿 8G 文本自动补全、问答、语句生成
GPT-2 2019年 15亿 16G 文本自动补全、问答、语句生成、命名实体识别、关系抽取
GPT-3 2020年 1750亿 32G 文本自动补全、问答、语句生成、命名实体识别、关系抽取、文本分类、翻译
GPT-3.5 2021年 1750亿 32G 基于 GPT-3 微调的一系列模型
  • 语言生成任务:文本自动补全、问答、语句生成
  • 语言理解任务:命名实体识别、关系抽取、文本分类、翻译

OpenAI API

模型能力

  • 执行各种自然语言任务的 GPT-3
  • 将自然语言翻译成代码的 Codex
  • 创建和编辑原始图像的 DALL·E

价格

  • 开始试用可在前 3 个月内使用 18 美元免费额度。
  • 1000 tokens 为 1 个计量单位
    • 一个汉字为 2 个 tokens
    • 大约 4 英文字母为 1 个 tokens
  • Tokenizer tool

Python 示例

调用 API 的参数 model: text-davinci-003 是基于 GPT-3 最好的模型,能力:复杂意图、因果关系、创建生成、搜索、总结等。

OpenWrt

DIY自己的软路由系统

LEDE

我买了一个使用 Intel 赛扬处理器的路由器。主要是为了搭梯子,2020年的时候网上编译好的系统不支持 TROJAN 协议,所以我自己使用 LEDE 编译。他的 SSR Plus+ 组件支持 SS/SSR/V2RAY/TROJAN 等协议.

  • Images built after May 31 2020 are based on Ubuntu 18.04.
  • x86 This image has 26G, and the dependent software packages and compiled binaries are in it. It can be used directly for x86, or it can be recompiled through simple configuration.
  • x86-bin This image contains only x86 binaries generated by compilation.

Compile your own LEDE system. Compile: docker run -it --name=lede gouchicao/lede:x86 git pull ./scripts/feeds update -a && .

在 MacBook Pro M2 Max 上安装 PyTorch

安装 PyTorch

sudo conda create --name pytorch python
conda activate pytorch

conda install pytorch torchvision torchaudio -c pytorch

安装每日构建版本

pip3 install --pre torch torchvision torchaudio --index-url https://download.pytorch.org/whl/nightly/cpu

升级

pip3 install --upgrade --pre torch torchvision torchaudio --index-url https://download.pytorch.org/whl/nightly/cpu

训练模型 import torch import torchvision import torchvision.transforms as transforms print(f"PyTorch version: {torch.

在 MacBook Pro M2 Max 上安装 TensorFlow

安装 TensorFlow

sudo conda create --name tensorflow python
conda activate tensorflow

# 不指定环境(-n),默认安装到base环境
sudo conda install -c apple -n tensorflow tensorflow-deps
pip install tensorflow-macos
pip install tensorflow-metal
sudo conda install notebook -y

pip install numpy  --upgrade
pip install pandas  --upgrade
pip install matplotlib  --upgrade
pip install scikit-learn  --upgrade
pip install scipy  --upgrade
pip install plotly  --upgrade

验证 import sys import tensorflow.keras import tensorflow as tf import platform print(f"Python Platform: {platform.

在 MacBook Pro M2 Max 上安装软件

Apple macOS Command

办公

WPS

Chrome 浏览器

Chrome 插件

Awesome Screenshot

Google 翻译

工具

数码测色计使用手册

LICEcap

My Zsh

sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"

V2rayU

Unzip One: RAR ZIP Extractor

FileZilla

macSVG

OmniGraffle

CleanMyMacX

ImageMagick(图像处理)

brew install imagemagick

asitop - Performance monitoring CLI tool for Apple Silicon

pip install asitop

jq

brew install jq

rar

brew install rar

unrar x <filename.rar>

开发 GitHub Desktop Visual Studi

在 MacBook Pro M2 Max 上构建开发环境

今天预订的 MacBook Pro M2Max 16寸 顶配 64G内存 2T硬盘到了,¥36097 。

硬件信息

芯片、内存

system_profiler SPHardwareDataType | head -n 9
Hardware:

    Hardware Overview:

      Model Name: MacBook Pro
      Model Identifier: Mac14,6
      Model Number: XXXXXXXXXXXX
      Chip: Apple M2 Max
      Total Number of Cores: 12 (8 performance and 4 efficiency)
      Memory: 64 GB

硬盘

system_profiler SPStorageDataType | head -n 8
Storage:

    Macintosh HD:

      Free: 1.37 TB (1,372,357,345,280 bytes)
      Capacity: 2 TB (1,995,218,165,760 bytes)
      Mount Point: /System/Volumes/Update/mnt1
      File System: APFS

更改主机名

sudo scutil --set HostName MBP

hostname
MBP

HomeBrew 安装 /bin/bash -c "$(

安装Kubernetes 1.26.0

Master 节点

查询可用安装包的信息

$ apt-cache madison kubeadm | head
kubeadm |  1.26.0-00 | https://mirrors.aliyun.com/kubernetes/apt kubernetes-xenial/main amd64 Packages
kubeadm |  1.25.5-00 | https://mirrors.aliyun.com/kubernetes/apt kubernetes-xenial/main amd64 Packages

切换 root 用户

su - root

更新

apt -y update
apt -y install docker-ce docker-ce-cli containerd.io
apt -y install kubelet=1.26.0-00 kubeadm=1.26.0-00 kubectl=1.26.0-00

安装 Kubernetes $ kubeadm reset -f $ kubeadm init --kubernetes-version=1.26.0 --image-repository=registry.aliyuncs.

学习【机器学习平台】建设的经验

快手技术 VP 王仲远对于 AI、大模型、深度学习的预测 2021-09-02

CV、Speech、NLP,背后主流的模型基本上都是基于 Transformer。在未来可能各方面的技术边界越来越模糊,事实上现在已经逐渐出现越来越多的多模态技术研究。技术融合变得门槛很低,但大家做的事越来越相像。

重要的研究方向

  • 大模型
  • 怎么让黑盒的深度学习跟知识能够进行融合变成可解释,然后增加常识。

近两年模型都已经到万亿级别了

  • Google Switch Transformer
  • OpenAI GPT-3
  • 阿里 M6

搜索系统是先以内容分析为主,再结合了用户行为;而推荐系统则是以用户行为为主,再尝试结合内容理解。 内容理解可以帮助推荐系统为用户做更加个性化的内容分发和匹配,探索如何更好地利用内容理解为推荐系统进一步提升个性化推荐能力。

怎么去考虑 AI 技术布局?(任何新技术都是类似的) 如果我们都只关注于未来三个月或半年就能落地的技术,那么很显然它是不具备可持续发展的。反之,如果只关注中长期才能见效的研究方向和研究项目的话,那么不确定性又会非常大,毕竟业务对于 AI 技术的渴求是非常强烈的。所以技术布局本质上是一个短期项目与长期项目配比的问题。

OpenVINO Deep Learning Workbench

使用 Docker 运行 DL Workbench

拉取镜像

docker pull openvino/workbench:2022.1

运行

docker run -p 0.0.0.0:5665:5665 --name workbench -it openvino/workbench:2022.1

浏览器访问

http://127.0.0.1:5665/

DL Workbench 工作流程

快速了解 DL Workbench 用户界面中的工作流程

参考资料

边缘硬件

研扬

Firefly

英特尔 Movidius 视觉处理器 (VPU)

基础知识

M.2

M.2原名为NGFF接口,标准名称为PCI Express M.2 Specification。它是为超极本(Ultrabook)量身定做的新一代接口标准,以取代原来基于mini PCIe改良而来的mSATA固态硬盘。无论是更小巧的规格尺寸还是更高的传输性能M.2都远胜于mSATA。随着SATA接口瓶颈不断凸显,越来越多的主板厂商也开始在自家产品线上预留M.2接口,主流的M.2接口有三种尺寸,分别是M.2 2242、2260、2280。

NVMe NVM Express(NVMe),或称非易失性内存

百度 EasyEdge 端与边缘 AI 服务平台

EasyEdge 端与边缘 AI 服务平台

使用 文档

EasyEdge 是基于百度飞桨轻量化推理框架 Paddle Lite 研发的端与边缘 AI 服务平台,能够帮助深度学习开发者将自建模型快速部署到设备端。可基于多种深度学习框架、网络结构的模型,快捷转换发布适配多种 AI 芯片与操作系统的端/边缘计算模型,支持纯离线计算/端云协同服务。

硬件平台适配

操作系统

  • Linux
  • Windows
  • Android
  • iOS

上传本地模型

模型属性

使用 Python 自动进行工作量估算

安装依赖库

pip install typer python-docx

编写脚本 workload-evaluation.py import os import logging import shutil import random import zipfile import openpyxl import typer from copy import copy from openpyxl.utils import rows_from_range # 日志设置 logger = logging.getLogger() logger.setLevel(logging.DEBUG) ## 文件输出 file_handler = logging.FileHandler("log.txt") file_handler.setLevel(logging.DEBUG) ## 控制台输出 stream_handler = logging.StreamHandler() stream_handler.setLevel(logging.DEBUG) formatter = logging.

Install TVM from Source

Ubuntu 下安装依赖包

sudo apt-get update
sudo apt-get install -y python3 python3-dev python3-setuptools gcc libtinfo-dev zlib1g-dev build-essential cmake libedit-dev libxml2-dev

获取源代码

git clone --recursive https://github.com/apache/tvm tvm

安装 LLVM

TVM 需要 LLVM 用于 CPU 代码生成,使用 LLVM 构建需要 LLVM 4.0 或更高版本。

LLVM Download Page

wget https://github.com/llvm/llvm-project/releases/download/llvmorg-11.0.0/clang+llvm-11.0.0-x86_64-linux-gnu-ubuntu-20.04.tar.xz
tar xvf clang+llvm-11.0.0-x86_64-linux-gnu-ubuntu-20.04.tar.xz
mv clang+llvm-11.0.0-x86_64-linux-gnu-ubuntu-20.04 llvm

构建共享库 创建 build 目录,将 cmake/config.

TVM

模型在使用 TVM 优化编译器框架进行转换时的步骤

from tvm.driver import tvmc
model = tvmc.load('resnet50-v2-7.onnx')
package = tvmc.compile(model, target="llvm")


from tvm.driver import tvmc
model = tvmc.load('sign.onnx') #Step 1: Load
package = tvmc.compile(model, target="llvm") #Step 2: Compile
result = tvmc.run(package, device="cpu") #Step 3: Run
print("Time :", timeit.default_timer() - starttime)


import onnx
import tvm
from tvm import relay
// ...

参考资料 The Deep Learning Compiler: A Comprehensive Survey 深度学习编译器整理 一篇关于深度学习编译器架构的综述论文 Getting Starting using TVMC P

面向边缘场景的 AI 芯片

NVIDIA Jetson

NVIDIA Jetson™ 是世界领先的平台,适用于自主机器和其他嵌入式应用程序。该平台包括 Jetson 模组(外形小巧的高性能计算机)、用于加速软件的 NVIDIA JetPack™ SDK,以及包含传感器、SDK、服务和产品的生态系统,从而加快开发速度。Jetson 与其他 NVIDIA 平台上所用的相同 AI 软件和云原生工作流相兼容,并能为客户提供构建软件定义的自主机器所需的性能和能效。 每个 NVIDIA Jetson 都是一个完整的系统模组 (SOM),其中包括 GPU、CPU、内存、电源管理和高速接口等。不同性能、能效和外形规格的组合满足各类行业的客户所需。Jetson 生态系统合作伙伴提供软件、硬件设计服务以及涵盖载板到完整系统的现成兼容产品,因此您可以借助 AI 嵌入式边缘设备更快地打入市场。

技术规格

参数 规格
性能 472 GFLOPS
最大功耗 10 W
显存 4 GB

英特尔 Movidius 视觉处理器 (VPU) 英特尔® Movidius™ Myriad™ X 视觉处理器为计算机视觉和深度神经网络推理应用提供出色性能。

ONNX Simplifier

onnxsim 本身只提供 constant folding/propagation(即消除结果恒为常量的算子)的能力,而图变换(即合并 conv 和 bn 等等)的能力是由 onnxsim 调用 onnx optimizer 的各种 pass 实现的。constant folding 和图变换同时使用时,很多隐藏的优化机会会被挖掘出来,这也是 onnxsim 优化效果出色的原因之一。例如 add(add(x, 1), 2) 在变换为 add(x, add(1, 2)) 之后就可以通过 constant folding 变为 add(x, 3),而 pad(conv(x, w, padding=0), add(1, 1)) 在经过 constant folding 变为 pad(conv(x, w, padding=0), 2) 后,就可以进一步融合成 conv(x, w, padding=2)。

安装

pip install -U pip
pip install onnx-simplifier

使用

命令

onnxsim input_onnx_model output_onnx_model

脚本集成 import onnx from onnxsim import simplify # load your predefined ONNX model model = onnx.

在 PyTorch 中融合卷积和批量标准化

融合卷积和批量标准化的原理

PyTorch 的实现 def fuse_conv_bn_eval(conv, bn, transpose=False): assert(not (conv.training or bn.training)), "Fusion only for eval!" fused_conv = copy.deepcopy(conv) fused_conv.weight, fused_conv.bias = \ fuse_conv_bn_weights(fused_conv.weight, fused_conv.bias, bn.running_mean, bn.running_var, bn.eps, bn.weight, bn.bias, transpose) return fused_conv def fuse_conv_bn_weights(conv_w, conv_b, bn_rm, bn_rv, bn_eps, bn_w, bn_b, transpose=False): if conv_b is None: conv_b = torch.zeros_like(bn_rm) if bn_w is None: bn_w = torch.

命令curl

下载文件

下载单个文件

curl http://book.d2l.ai/_images/catdog.jpg -o catdog.jpg

下载多个文件

curl https://download.01.org/opencv/2021/openvinotoolkit/2021.1/open_model_zoo/models_bin/1/face-detection-retail-0004/FP32/face-detection-retail-0004.xml https://download.01.org/opencv/2021/openvinotoolkit/2021.1/open_model_zoo/models_bin/1/face-detection-retail-0004/FP32/face-detection-retail-0004.bin -o face-detection-retail-0004.xml -o face-detection-retail-0004.bin

下载文件并创建目录 curl --create-dirs https://download.01.org/opencv/2021/openvinotoolkit/2021.

OpenVINO Benchmark Python Tool

性能指标评测工具

该工具使用卷积网络执行推理。性能可以测量两种推理模式:

  • 同步(面向延迟 Latency)
  • 异步(面向吞吐量 Throughput)

帮助信息 -i PATHS_TO_INPUT [PATHS_TO_INPUT ...], --paths_to_input PATHS_TO_INPUT [PATHS_TO_INPUT ...] Optional. Path to a folder with images and/or binaries or to specific image or binary file.It is also allowed to map files to network inputs: input_1:file_1/dir1,file_2/dir2,input_4:file_4/dir4 input_2:file_3/dir3 -m PATH_TO_MODEL, --path_to_model PATH_TO_MODEL Required. Path to an .xml/.onnx file with a trained model or to a .blob file with a trained compiled model. -d TARGET_DEVICE, --target_device TARGET_DEVICE Optional.