21/12/2023
Полухін Андрій
Efficiency in AI:
Практичні поради з оптимізації ШІ
DOU AI Meetup, Kyiv
Про мене
Agenda
Переваги
Переваги
Переваги
Недоліки
Переваги
Недоліки
Альтернативи ChatGPT
Альтернативи ChatGPT
Недоліки
Open Source LLM
Open Source LLM
Недоліки
Переваги
Open Source LLM
Недоліки
Переваги
Open Source LLM
Недоліки
Переваги
Open Source LLM
and more: Chatbot Arena, ollama, Open LLM Leaderboard, vLLM
Neural Network Inference
Any neural network
e.g. YOLO, Llama2, Stable Diffusion, Whisper
Neural Network Inference
Any neural network
e.g. YOLO, Llama2, Stable Diffusion, Whisper
ML Framework
Neural Network Inference
Any neural network
e.g. YOLO, Llama2, Stable Diffusion, Whisper
Data
ML Framework
Pre Processing
Post Processing
Inference
Pipeline
Neural Network Inference
Any neural network
e.g. YOLO, Llama2, Stable Diffusion, Whisper
Data
ML Framework
Pre Processing
Post Processing
Inference
Pipeline
Neural Network Inference
Any neural network
e.g. YOLO, Llama2, Stable Diffusion, Whisper
Data
ML Framework
Pre Processing
Post Processing
Inference
Pipeline
Neural Network Inference
Any neural network
e.g. YOLO, Llama2, Stable Diffusion, Whisper
Data
ML Framework
Pre Processing
Post Processing
Inference
Pipeline
Neural Network Inference
Виберіть фреймворк
Виберіть фреймворк
Виберіть фреймворк
Виберіть фреймворк
Any neural network
e.g. YOLO, Llama2, Stable Diffusion, Whisper
Data
ML Framework
Pre Processing
Post Processing
Inference
Pipeline
Neural Network Inference
Model Architecture
Model Architecture
Model Architecture
Model Architecture
Model Distillation
The teacher-student framework for knowledge distillation
Model Distillation
pip3 install torchdistill
Model Pruning
Pruning: Before and After
Model Pruning
Model Pruning
from neural_compressor.training import prepare_pruning, WeightPruningConfigconfig = WeightPruningConfig(configs)
prepare_pruning(model, config, optimizer)
for epoch in range(num_train_epochs):
model.train()
for step, batch in enumerate(train_dataloader):
outputs = model(**batch)
loss = outputs.loss
loss.backward()
optimizer.step()
lr_scheduler.step()
model.zero_grad()
pip3 install neural-compressor
Half Precision fp16
Figure represents comparison of FP16 (half precision floating points)
and FP32 (single precision floating points).
Half Precision fp16
# PyTorch
import torch
model = model.half() # Convert model to half precision
input_data = input_data.half() # Convert input data to half precision
# TensorFlow
import tensorflow as tf
from tensorflow.keras.mixed_precision import experimental as mixed_precision
policy = mixed_precision.Policy('mixed_float16')
mixed_precision.set_policy(policy)
# TensorRT
import tensorrt as trt
builder = trt.Builder(TRT_LOGGER)
builder.fp16_mode = True
Model Quantization
8-bit Integer (INT8)
Model Quantization
Quantization technique
Model Quantization
Deploy Just in 4 Lines with MQBench
model = models.__dict__["resnet18"](pretrained=True)
model = prepare_by_platform(model, BackendType.Tensorrt)
enable_calibration(model) # turn on calibration
for i, batch in enumerate(data): # do forward procedures
...
enable_quantization(model) # turn on actually quantization
input_shape={'data': [10, 3, 224, 224]}
convert_deploy(model, backend, input_shape) # model export
int4
MLPerf v0.5 Inference results for data center server form factors and offline scenario retrieved from www.mlperf.org on Nov. 6, 2019 (Closed Inf-0.5-25 and Inf-0.5-27 for INT8, Open Inf-0.5-460 and Inf-0.5-462 for INT4). Per-processor performance is calculated by dividing the primary metric of total performance by number of accelerators reported. MLPerf name and logo are trademarks.
Приклади
YOLOv8, x3 speed up
YOLOv8, x3 speed up
Specifications:
YOLOv8, x3 speed up
YOLO v8 m
56 FPS
Specifications:
YOLOv8, x3 speed up
YOLO v8 m
56 FPS
Specifications:
YOLO v8 m
91 FPS
Half Precision
YOLOv8, x3 speed up
YOLO v8 m
56 FPS
Specifications:
YOLO v8 m
91 FPS
Half Precision
YOLO v8 m
57 FPS
TensorRT
YOLOv8, x3 speed up
YOLO v8 m
56 FPS
YOLO v8 m
143 FPS
YOLO v8 m
91 FPS
YOLO v8 m
57 FPS
TensorRT
Half Precision
Half Precision
TensorRT
x3 speed up
Specifications:
YOLOv8, x3 speed up
# Code to optimize
import ultralytics
model = ultralytics.YOLO("yolov8m")
model.export(format="engine", imgsz=1280, batch=64, half=True)
# Or, use https://github.com/NVIDIA-AI-IOT/torch2trt
Consumer PC GPT
Consumer PC GPT
# Code in Python
from gpt4all import GPT4All
model = GPT4All("orca-mini-3b-gguf2-q4_0.gguf")
output = model.generate("The capital of France is ", max_tokens=3)
print(output)
The GPT4All Chat UI supports models from all newer versions of llama.cpp with GGUF models including the Mistral, LLaMA2, LLaMA, OpenLLaMa, Falcon, MPT, Replit, Starcoder, and Bert architectures.
Nomic Vulkan Benchmarks: Single batch item inference token throughput benchmarks.
Q/A