State of GPT - Andrej Karpathy

介绍

Learn about the training pipeline of GPT assistants like ChatGPT, from tokenization to pretraining, supervised finetuning, and Reinforcement Learning from Human Feedback (RLHF). Dive deeper into practical techniques and mental models for the effective use of these models, including prompting strategies, finetuning, the rapidly growing ecosystem of tools, and their future extensions.

了解 ChatGPT 等 GPT 助手的训练管道,从标记化到预训练、监督微调和人类反馈强化学习 (RLHF)。 深入研究有效使用这些模型的实用技术和心智模型,包括提示策略、微调、快速增长的工具生态系统及其未来的扩展。

ChatGPT Prompt Engineering for Developers

ChatGPT Prompt Engineering for Developers 由Isa Fulford(OpenAI)和Andrew Ng(DeepLearning.AI)教授的课程将描述 LLM 的工作原理,提供快速工程的最佳实践,并展示 LLM API 如何用于各种任务的应用程序。

面向开发人员的 ChatGPT 提示工程

Instroduction(介绍)

Guidelines(准则)

帮助函数 import openai import os openai.api_key = os.getenv('OPENAI_API_KEY') def get_completion(prompt, model="gpt-3.5-turbo"): messages = [{"role": "user", "content": prompt}] response = openai.ChatCompletion.create( model=model, messages=messages, temperature=0, # this is the degree of randomness of the model's output ) return response.choices[0].

Whisper 语音识别

Whisper

功能

  • 将音频转录成音频所使用的任何语言。
  • 将音频翻译并转录成英文。

文件上传目前限制为 25 MB,并且支持以下输入文件类型:mp3, mp4, mpeg, mpga, m4a, wav, webm.

语音内容

Mira Murati 是一位对人工智能技术充满热情的科技领袖,她的理念和影响对人工智能技术的发展和应用产生了深远的影响。

她认为人工智能技术应该是以人为本的,强调人工智能技术应该是一种能够服务于人类的工具,而不是取代人类的工具。

她指出,人工智能技术的最终目的是为人类服务,因此人工智能技术应该以人类的利益和需求为中心,以解决人类面临的实际问题。人工智能技术的应用需要深入了解人类社会的需要和价值,将其应用到真正有意义的领域中。

OpenAI Whisper

安装 OpenAI

!pip install -U openai

测试

语音识别

import openai
audio_file= open("data/audios/test.m4a", "rb")
transcript = openai.Audio.transcribe("whisper-1", audio_file)
print(transcript["text"])

Miramurati是一位对人工智能技术充满热情的科技领袖 他的

Stable Diffusion

Stable Diffusion

模型 Stable Diffusion v1-5

数据集 LAION-5B

一个由 58.5 亿个 CLIP 过滤的图像-文本对组成的数据集

CLIP Retrieval

工作原理是将文本查询转换为 CLIP 嵌入,然后使用该嵌入来查询剪辑图像嵌入的 knn 索引,在搜索演示中搜索数据集。

Stable Diffusion GUI

Diffusers

🤗 Diffusers 是最先进的预训练扩散模型的首选库,用于生成图像、音频,甚至分子的 3D 结构。无论您是在寻找简单的推理解决方案,还是想训练自己的扩散模型,🤗 Diffusers 都是一个支持两者的模块化工具箱。

知识扩展

Latent Representation

数据中的潜在特征表示,这些特征可能不易直接观察到,但对于模型的学习和预测等任务具有重要意义。例如,在图像识别中,一张图片的颜色、形状、纹理等特征可以被视为潜在特征表示。

Latent Space

由模型自动生成的潜在特征空间,其中每个点都表示一种可能的特征组合。在深度学习和人工智能领域,常常使用自编码器等技术来学习并探索数据的潜在特征空间,以期获得更深入的理解和更好的应用效果。

参考资料 AutoFaiss Multimodal search

Docker 构建多平台镜像

多平台构建器

当前构建器实例是驱动程序 docker-container,可以同时指定多个平台。在这种情况下,它会构建一个清单列表,其中包含所有指定架构的镜像。在构建的时候可以并行构建多个架构的镜像。

docker run 当您在使用此镜像时 docker service,Docker 会根据节点的平台选择正确的镜像。

有个缺点:必须发布到 Docker Hub 或者私有仓库,因为 Docker 不支持多架构的本地镜像。

查看构建器 docker buildx ls NAME/NODE DRIVER/ENDPOINT STATUS BUILDKIT PLATFORMS default docker default default running v0.11.6+616c3f613b54 linux/arm64, linux/riscv64, linux/ppc64le, linux/s390x, linux/386, linux/mips64, linux/arm/v7, linux/arm/v6, linux/amd64, linux/amd64/v2 desktop-linux * docker desktop-linux desktop-linux running v0.11.

macOS Docker

今天用 Docker 构建镜像,突然就挂了。重启 Docker,发现 Docker 无法启动了。

出现的错误

🐳 Building platen-switch:arm64
[+] Building 0.0s (2/2) FINISHED                                                                                                                                                            
 => [internal] load build definition from Dockerfile                                                                                                                                   0.0s
 => => transferring dockerfile: 69B                                                                                                                                                    0.0s
 => [internal] load .dockerignore                                                                                                                                                      0.0s
 => => transferring context: 2B                                                                                                                                                        0.0s
ERROR: failed to solve: rpc error: code = Unknown desc = failed to solve with frontend dockerfile.v0: failed to read dockerfile: failed to create temp dir: mkdir /var/lib/docker/tmp/buildkit-mount1477620899: no space left on device

分析问题 运行诊断工具 com.docker.

Ultralytics YOLOv8 推理速度对比

CPU

服务器信息

lscpu

Architecture:                    x86_64
CPU op-mode(s):                  32-bit, 64-bit
Byte Order:                      Little Endian
Address sizes:                   46 bits physical, 48 bits virtual
CPU(s):                          40
On-line CPU(s) list:             0-39
Thread(s) per core:              2
Core(s) per socket:              10
Socket(s):                       2
NUMA node(s):                    2
Vendor ID:                       GenuineIntel
CPU family:                      6
Model:                           79
Model name:                      Intel(R) Xeon(R) CPU E5-2640 v4 @ 2.40GHz
Stepping:                        1
CPU MHz:                         1201.687
CPU max MHz:                     3400.0000
CPU min MHz:                     1200.0000
BogoMIPS:                        4788.86
Virtualization:                  VT-x
L1d cache:                       640 KiB
L1i cache:                       640 KiB
L2 cache:                        5 MiB
L3 cache:                        50 MiB
NUMA node0 CPU(s):               0-9,20-29
NUMA node1 CPU(s):               10-19,30-39
Vulnerability Itlb multihit:     KVM: Mitigation: Split huge pages
Vulnerability L1tf:              Mitigation; PTE Inversion; VMX conditional cache flushes, SMT vulnerable
Vulnerability Mds:               Mitigation; Clear CPU buffers; SMT vulnerable
Vulnerability Meltdown:          Mitigation; PTI
Vulnerability Spec store bypass: Mitigation; Speculative Store Bypass disabled via prctl and seccomp
Vulnerability Spectre v1:        Mitigation; usercopy/swapgs barriers and __user pointer sanitization
Vulnerability Spectre v2:        Mitigation; Full generic retpoline, IBPB conditional, IBRS_FW, STIBP conditional, RSB filling
Vulnerability Srbds:             Not affected
Vulnerability Tsx async abort:   Mitigation; Clear CPU buffers; SMT vulnerable
Flags:                           fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nop
                                 l xtopology nonstop_tsc cpuid aperfmperf pni pclmulqdq dtes64 ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c 
                                 rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb cat_l3 cdp_l3 invpcid_single pti intel_ppin ssbd ibrs ibpb stibp tpr_shadow vnmi flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 hle avx2 sme
                                 p bmi2 erms invpcid rtm cqm rdt_a rdseed adx smap intel_pt xsaveopt cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local dtherm ida arat pln pts md_clear flush_l1d

macOS 下的 __MACOSX 目录和 .DS_Store 文件

.DS_Store 文件

.DS_Store 是 Desktop Services Store 的缩写。

.DS_Store 是 macOS 操作系统中隐藏的文件,它存储有关文件夹的元数据,例如文件夹中的文件位置、文件夹的显示选项和自定义图标等信息。这些元数据是用来帮助操作系统更快地显示文件夹中的内容,并记住用户的偏好设置。这些文件只是本地的,不会在网络文件共享时传输,因此不会影响其他操作系统用户。

__MACOSX 目录

当你在 Mac 电脑上创建一个压缩文件时,系统会自动在压缩文件中添加一个名为 __MACOSX 的目录。该目录包含了 Mac 操作系统专有的一些文件,如 .DS_Store 等。这些文件不会对压缩文件的解压缩造成影响,但它们可能会在其他操作系统上解压缩时出现问题,例如在 Windows 上解压缩时可能会显示 __MACOSX 目录或 .DS_Store 文件。为了避免这种情况,你可以在创建压缩文件时选择不包含 Mac 专有文件,或者在解压缩时手动删除 __MACOSX 目录和 .DS_Store 文件。

删除 __MACOSX 目录和 .DS_Store 文件 方法一 find . -name '__MACOSX' -exec rm -rf {} ; -o -name '.

构建容器化 Python 应用程序

这里使用 Ultralytics Serving 作为示例,它是一个基于 FastAPIUltralytics YOLOv8 的模型推理服务。

选择 Python 镜像

Tag Python Version OS Version Size
3.10 3.10 Debian GNU/Linux 11 (bullseye) 861MB
3.10-slim 3.10 Debian GNU/Linux 11 (bullseye) 114MB
3.10-alpine 3.10 Alpine Linux 3.15.0 44.7MB

克隆 Ultralytics Serving

git clone https://github.com/gouchicao/ultralytics-serving.git
cd ultralytics-serving

编写 Dockerfile

采用两阶段构建,第一阶段安装依赖环境和编译应用,第二阶段发布应用。第二阶段可以使用小一点的镜像,比如 python:3.10-slimpython:3.10-alpine

普通版本 FROM python:3.10 AS builder ENV APP_HOME=/ultralytics-serving WORKDIR ${APP_HOME} # 提前安装,因为 cpu 版本需要指定 index-url。

加速 Docker 构建镜像

查看镜像信息

操作系统版本

cat /etc/os-release 
  • Debian
PRETTY_NAME="Debian GNU/Linux 11 (bullseye)"
NAME="Debian GNU/Linux"
VERSION_ID="11"
VERSION="11 (bullseye)"
VERSION_CODENAME=bullseye
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"
  • Ubuntu
PRETTY_NAME="Ubuntu Jammy Jellyfish (development branch)"
NAME="Ubuntu"
VERSION_ID="22.04"
VERSION="22.04 (Jammy Jellyfish)"
VERSION_CODENAME=jammy
ID=ubuntu
ID_LIKE=debian
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
UBUNTU_CODENAME=jammy

Python 配置共享软件包缓存

共享软件包缓存的好处是,一旦用户已经下载了软件包的特定版本,它将不会再次下载并存储在单独的缓存中。这节省了磁盘使用量并加快了安装速度,因为它不需要再次下载软件包。

Conda 查看 Conda 当前环境的信息 conda info active environment : base active env location : /opt/miniconda shell level : 1 user config file : /Users/junjian/.condarc populated config files : conda version : 23.3.1 conda-build version : not installed python version : 3.10.9.final.0 virtual packages : __archspec=1=arm64 __osx=13.2.1=0 __unix=0=0 base environment : /opt/miniconda (writable) conda av data dir : /opt/miniconda/etc/conda conda av metadata url : None channel URLs : https://repo.anaconda.

讯飞星火测试

Spark Desk 是讯飞星火认知大模型的英文名称。

👍零样本分类

❓ “这个手机的功能不好用”这是好评还是差评?
💬 这个手机的功能不好用,是差评。

👎少样本分类

❓ 电脑:3C;手机:3C;铅笔:
💬 3C;

👍英语语法更正

❓ Correct this to standard English:

She no went to the market.
💬 She did not go to the market.

ChatGPT 还会解释语法的问题

👍翻译

英译中

❓ What rooms do you have available? 翻译成中文
💬 你有哪些房间可用?

中译英

❓ 您好,您想要预订哪些房型呢?翻译成英文
💬 Hello, which room type would you like to book?

👍阅读理解 ❓ 北京市卫生健康委副主任、新闻发言人李昂通报:4月18日下午,长峰医院突发火情,市卫生健康委即刻启动应急预案,迅速调集29辆救护车300余人次急救力量,及时赶赴现场,全力开展医疗救援和转运工作。截至当日15时30分,共转运伤员71名,分别送至解放军总医院第一医学中心、解放军总医院第五医学中心南、北院区、北京世纪坛医院、航天中心医院、电力医院、玉泉医院、丰台区医院、右安门医院等9家医疗机构救治。涉灾病房楼其余住院患者均已妥善安置。

OpenAI API Documentation Speech to Text

开发文档

Speech to text

API reference Audio

查看音频文件信息

file

data/podcast_clip.mp3: Audio file with ID3 version 2.4.0, contains: MPEG ADTS, layer III, v1, 64 kbps, 44.1 kHz, Stereo

ffprobe ffprobe -hide_banner data/podcast_clip.mp3 Input #0, mp3, from 'data/podcast_clip.mp3': Metadata: major_brand : M4A minor_version : 512 compatible_brands: M4A isomiso2 date : 2023-02-06 14:59 title : "Clip created on ListenNotes.com" encoder : Lavf58.76.100 Duration: 00:03:00.04, start: 0.025057, bitrate: 128 kb/s Stream #0:0: Audio: mp3, 44100 Hz, stereo, fltp, 128 kb/s Metadata: encoder : Lavc58.

PaddleSpeech 快速入门

PaddleSpeech

介绍

PaddleSpeech 是基于飞桨 PaddlePaddle 的语音方向的开源模型库,用于语音和音频中的各种关键任务的开发,包含大量基于深度学习前沿和有影响力的模型。

功能

  • 语音识别
  • 语音合成
  • 声音分类
  • 声纹提取
  • 标点恢复
  • 语音翻译

学习

安装

conda create -n paddlespeech python==3.10.9
conda activate paddlespeech

pip install paddlepaddle -i https://mirror.baidu.com/pypi/simple
pip install pytest-runner paddlespeech

pip install "numpy<1.24"

测试数据下载

wget -c https://paddlespeech.bj.bcebos.com/PaddleAudio/zh.wav
wget -c https://paddlespeech.bj.bcebos.com/PaddleAudio/en.wav

FAQ paddlespeech asr --lang zh --input zh.

LangChain - Chain

Chain

链允许我们将多个组件组合在一起以创建一个单一的、连续的应用程序。我们可以通过将多个链组合在一起,或者通过将链与其他组件组合来构建更复杂的链。

LLMChain

LLMChain 是一个简单的链,它接受一个提示模板,用用户输入格式化它并返回来自 LLM 的响应。

语言模型(text-davinci-003) from langchain.chains import LLMChain from langchain.llms import OpenAI from langchain.prompts import PromptTemplate llm = OpenAI(temperature=0.9) prompt = PromptTemplate(input_variables=["product"], template="What is a good name for a company that makes {product}?

LangChain 快速入门

LangChain

通过可组合性使用 LLM 构建应用程序

介绍

大型语言模型 (LLM) 正在成为一种变革性技术,使开发人员能够构建他们以前无法构建的应用程序。 但是,单独使用这些 LLM 往往不足以创建真正强大的应用程序——当您可以将它们与其他计算或知识来源相结合时,真正的力量就来了。

Documentation

安装

pip install langchain
# or
conda install langchain -c conda-forge

配置环境

使用 LangChain 通常需要与一个或多个模型提供者、数据存储、api 等集成。

对于这个例子,将使用 OpenAI 的 API

pip install openai
export OPENAI_API_KEY="..."

LLMs:从语言模型获得预测结果

在这个例子中,我们可能希望输出更加随机,所以将 temperature 设置的更高一些。

from langchain.llms import OpenAI

llm = OpenAI(temperature=0.9)

text = "一家生产彩色袜子的公司取什么名字好?"
print(llm(text))
可以取名为:Colorful Socks Factory。

提示模板(Prompt Templates):管理 LLM 的提示 from la