{"id":477847,"date":"2026-04-28T21:48:17","date_gmt":"2026-04-28T21:48:17","guid":{"rendered":"https:\/\/savepearlharbor.com\/?p=477847"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=477847","title":{"rendered":"\u041a\u0430\u043a \u044f \u043d\u0430\u043f\u0438\u0441\u0430\u043b \u0434\u0432\u0438\u0436\u043e\u043a \u0440\u0430\u0441\u043f\u043e\u0437\u043d\u0430\u0432\u0430\u043d\u0438\u044f \u043b\u0438\u0446 \u043d\u0430 C, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u0431\u043e\u0433\u043d\u0430\u043b ONNX Runtime"},"content":{"rendered":"<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u041f\u043e\u043b\u0433\u043e\u0434\u0430 \u043d\u0430\u0437\u0430\u0434 \u044f \u043d\u0430\u0447\u0430\u043b \u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043d\u0435\u0439\u0440\u043e\u0441\u0435\u0442\u044c EdgeFace-XS \u0438\u0437 ONNX \u0432 \u0447\u0438\u0441\u0442\u044b\u0439 C. \u0414\u0443\u043c\u0430\u043b \u2014 \u0433\u0440\u0430\u0444 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0439, 1.77M \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432, \u0447\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u0439\u0442\u0438 \u043d\u0435 \u0442\u0430\u043a? \u041f\u0435\u0440\u0432\u044b\u0439 \u043d\u0430\u0438\u0432\u043d\u044b\u0439 \u043f\u043e\u0440\u0442 \u0432\u044b\u0434\u0430\u043b\u00a0<strong>24\u043c\u0441<\/strong>. ONNX Runtime \u2014\u00a0<strong>3.9\u043c\u0441<\/strong>. \u0412 6 \u0440\u0430\u0437 \u043c\u0435\u0434\u043b\u0435\u043d\u043d\u0435\u0435. \u0410 \u043f\u043e\u0442\u043e\u043c \u043d\u0430\u0447\u0430\u043b\u0430\u0441\u044c \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044f.<\/p>\n<h3>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442<\/h3>\n<div>\n<div class=\"table\">\n<table>\n<tbody>\n<tr>\n<th>\n<p align=\"left\">\n<\/th>\n<th>\n<p align=\"left\">FaceX<\/p>\n<\/th>\n<th>\n<p align=\"left\">ONNX Runtime 1.23<\/p>\n<\/th>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">\u041c\u0435\u0434\u0438\u0430\u043d\u0430<\/p>\n<\/td>\n<td>\n<p align=\"left\">3.0 \u043c\u0441<\/p>\n<\/td>\n<td>\n<p align=\"left\">3.9 \u043c\u0441<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">\u041c\u0438\u043d\u0438\u043c\u0443\u043c<\/p>\n<\/td>\n<td>\n<p align=\"left\">2.87 \u043c\u0441<\/p>\n<\/td>\n<td>\n<p align=\"left\">3.18 \u043c\u0441<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">\u0420\u0430\u0437\u043c\u0435\u0440 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438<\/p>\n<\/td>\n<td>\n<p align=\"left\">148 \u041a\u0411<\/p>\n<\/td>\n<td>\n<p align=\"left\">28 \u041c\u0411<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">\u0417\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u043d\u0435\u0442<\/p>\n<\/td>\n<td>\n<p align=\"left\">Python + onnxruntime<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">\u0422\u043e\u0447\u043d\u043e\u0441\u0442\u044c LFW<\/p>\n<\/td>\n<td>\n<p align=\"left\">99.73%<\/p>\n<\/td>\n<td>\n<p align=\"left\">99.73%<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<blockquote>\n<p>\u0427\u0438\u0441\u0442\u044b\u0439 C \u0441 SIMD \u0438\u043d\u0442\u0440\u0438\u043d\u0441\u0438\u043a\u0430\u043c\u0438 \u043e\u0431\u0433\u043e\u043d\u044f\u0435\u0442 ONNX Runtime \u043d\u0430\u00a0<strong>23%<\/strong>. \u041e\u0434\u0438\u043d \u0438 \u0442\u043e\u0442 \u0436\u0435 CPU (i5-11500), \u043e\u0434\u043d\u0430 \u043c\u043e\u0434\u0435\u043b\u044c, \u043e\u0434\u043d\u0438 \u0432\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435.<\/p>\n<\/blockquote>\n<h3>\u041f\u0443\u0442\u044c \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438: 24\u043c\u0441 \u2192 3\u043c\u0441<\/h3>\n<h4>\u042d\u0442\u0430\u043f 0: \u041f\u0440\u043e\u0444\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435<\/h4>\n<p>\u0417\u0430\u043c\u0435\u0440\u0438\u043b \u043a\u0430\u0436\u0434\u0443\u044e \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044e \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e. \u0413\u043b\u0430\u0432\u043d\u044b\u0439 \u0441\u044e\u0440\u043f\u0440\u0438\u0437:<\/p>\n<blockquote>\n<p><strong>\u041c\u0430\u0442\u0440\u0438\u0447\u043d\u043e\u0435 \u0443\u043c\u043d\u043e\u0436\u0435\u043d\u0438\u0435 \u2014 \u0432\u0441\u0435\u0433\u043e 6% \u043e\u0442 \u043e\u0431\u0449\u0435\u0433\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0438\u043d\u0444\u0435\u0440\u0435\u043d\u0441\u0430.<\/strong><\/p>\n<\/blockquote>\n<p>\u041d\u0430\u0441\u0442\u043e\u044f\u0449\u0438\u0435 \u0443\u0431\u0438\u0439\u0446\u044b \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438:<\/p>\n<div>\n<div class=\"table\">\n<table>\n<tbody>\n<tr>\n<th>\n<p align=\"left\">\u041e\u043f\u0435\u0440\u0430\u0446\u0438\u044f<\/p>\n<\/th>\n<th>\n<p align=\"left\">\u0414\u043e\u043b\u044f<\/p>\n<\/th>\n<th>\n<p align=\"left\">\u041f\u0440\u043e\u0431\u043b\u0435\u043c\u0430<\/p>\n<\/th>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">Depthwise conv<\/p>\n<\/td>\n<td>\n<p align=\"left\">~30%<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0422\u0440\u0430\u043d\u0441\u043f\u043e\u0437\u044b HWC\u2194CHW \u043d\u0430 \u043a\u0430\u0436\u0434\u043e\u043c \u0431\u043b\u043e\u043a\u0435<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">LayerNorm \u00d7 17<\/p>\n<\/td>\n<td>\n<p align=\"left\">~16%<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0421\u043a\u0430\u043b\u044f\u0440\u043d\u044b\u0439 mean\/variance<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">GELU \u00d7 17<\/p>\n<\/td>\n<td>\n<p align=\"left\">~10%<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u041d\u0430\u0438\u0432\u043d\u044b\u0439\u00a0<code>tanh()<\/code>\u00a0\u0447\u0435\u0440\u0435\u0437 math.h<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">\u0422\u0440\u0430\u043d\u0441\u043f\u043e\u0437\u044b \u043f\u0430\u043c\u044f\u0442\u0438<\/p>\n<\/td>\n<td>\n<p align=\"left\">~8%<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u041b\u0438\u0448\u043d\u0438\u0435 \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">MatMul<\/p>\n<\/td>\n<td>\n<p align=\"left\">~6%<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0423\u0436\u0435 \u0431\u044b\u0441\u0442\u0440\u043e<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<h4>\u042d\u0442\u0430\u043f 1: SIMD \u044f\u0434\u0440\u0430 (24\u043c\u0441 \u2192 8\u043c\u0441)<\/h4>\n<p>\u041d\u0430\u043f\u0438\u0441\u0430\u043b AVX2 \u0432\u0435\u0440\u0441\u0438\u0438 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438:<\/p>\n<ul>\n<li>\n<p><strong>LayerNorm<\/strong>\u00a0\u2014 fused mean+variance \u0432 \u043e\u0434\u043d\u043e\u043c \u043f\u0440\u043e\u0445\u043e\u0434\u0435. \u0412\u043c\u0435\u0441\u0442\u043e \u0434\u0432\u0443\u0445 \u0446\u0438\u043a\u043b\u043e\u0432 \u043f\u043e \u043f\u0430\u043c\u044f\u0442\u0438 \u2014 \u043e\u0434\u0438\u043d \u0441\u00a0<code><em>mm256<\/em>fmadd_ps<\/code>\u00a0\u0434\u043b\u044f \u043d\u0430\u043a\u043e\u043f\u043b\u0435\u043d\u0438\u044f \u0441\u0443\u043c\u043c\u044b \u0438 \u0441\u0443\u043c\u043c\u044b \u043a\u0432\u0430\u0434\u0440\u0430\u0442\u043e\u0432<\/p>\n<\/li>\n<li>\n<p><strong>GELU<\/strong>\u00a0\u2014 \u0432\u044b\u043a\u0438\u043d\u0443\u043b\u00a0<code>tanh()<\/code>. \u0420\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043b exact erf \u0447\u0435\u0440\u0435\u0437 \u043f\u043e\u043b\u0438\u043d\u043e\u043c\u0438\u0430\u043b\u044c\u043d\u0443\u044e \u0430\u043f\u043f\u0440\u043e\u043a\u0441\u0438\u043c\u0430\u0446\u0438\u044e \u0410\u0431\u0440\u0430\u043c\u043e\u0432\u0438\u0446\u0430-\u0421\u0442\u0435\u0433\u0443\u043d\u0430 (\u0444\u043e\u0440\u043c\u0443\u043b\u0430 7.1.26) \u0441 \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u044b\u043c\u00a0<code><em>mm256<\/em>exp_ps<\/code>\u00a0\u043d\u0430 8 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0437\u0430 \u0442\u0430\u043a\u0442<\/p>\n<\/li>\n<li>\n<p><strong>Depthwise conv<\/strong>\u00a0\u2014 \u043f\u0435\u0440\u0435\u0432\u0451\u043b \u0432\u0435\u0441\u044c \u0434\u0432\u0438\u0436\u043e\u043a \u043d\u0430 \u043d\u0430\u0442\u0438\u0432\u043d\u044b\u0439 HWC layout. \u041d\u0438 \u043e\u0434\u043d\u043e\u0433\u043e \u0442\u0440\u0430\u043d\u0441\u043f\u043e\u0437\u0430 \u0432\u043e \u0432\u0441\u0451\u043c forward pass<\/p>\n<\/li>\n<\/ul>\n<h4>\u042d\u0442\u0430\u043f 2: MatMul (8\u043c\u0441 \u2192 5\u043c\u0441)<\/h4>\n<ul>\n<li>\n<p><strong>FP32 packed column-panel<\/strong>: \u0432\u0435\u0441\u0430 \u043f\u0435\u0440\u0435\u043f\u0430\u043a\u043e\u0432\u0430\u043d\u044b \u0432 \u0444\u043e\u0440\u043c\u0430\u0442\u00a0<code>[ceil(N\/8), K, 8]<\/code>\u00a0\u2014 \u043a\u0430\u0436\u0434\u044b\u0439 \u0441\u0442\u043e\u043b\u0431\u0435\u0446-\u043f\u0430\u043d\u0435\u043b\u044c \u043f\u043e\u043c\u0435\u0449\u0430\u0435\u0442\u0441\u044f \u0432 L1 \u043a\u044d\u0448<\/p>\n<\/li>\n<li>\n<p><strong>INT8 GEMM \u043c\u0438\u043a\u0440\u043e\u044f\u0434\u0440\u043e<\/strong>\u00a0\u0441 per-channel \u043a\u0432\u0430\u043d\u0442\u0438\u0437\u0430\u0446\u0438\u0435\u0439:<\/p>\n<ul>\n<li>\n<p>AVX2:\u00a0<code>vpmaddubsw<\/code>\u00a0\u0441 \u00b163 clamping \u0434\u043b\u044f \u043f\u0440\u0435\u0434\u043e\u0442\u0432\u0440\u0430\u0449\u0435\u043d\u0438\u044f s16 \u043d\u0430\u0441\u044b\u0449\u0435\u043d\u0438\u044f<\/p>\n<\/li>\n<li>\n<p>AVX-512 VNNI:\u00a0<code>vpdpbusd<\/code>\u00a0\u2014 \u043d\u0430\u0442\u0438\u0432\u043d\u044b\u0435 INT8 dot products \u0431\u0435\u0437 \u043d\u0430\u0441\u044b\u0449\u0435\u043d\u0438\u044f<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>Thread pool<\/strong>\u00a0\u2014 lock-free \u0441 work-stealing \u0447\u0435\u0440\u0435\u0437 \u0430\u0442\u043e\u043c\u0430\u0440\u043d\u044b\u0439 \u0441\u0447\u0451\u0442\u0447\u0438\u043a \u0438\u00a0<code>WaitOnAddress<\/code>\/<code>futex<\/code><\/p>\n<\/li>\n<\/ul>\n<h4>\u042d\u0442\u0430\u043f 3: \u041f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0435 \u043c\u0438\u043b\u043b\u0438\u0441\u0435\u043a\u0443\u043d\u0434\u044b (5\u043c\u0441 \u2192 3\u043c\u0441)<\/h4>\n<ul>\n<li>\n<p>\u0423\u0431\u0440\u0430\u043b\u00a0<strong>\u0432\u0441\u0435<\/strong>\u00a0\u0442\u0440\u0430\u043d\u0441\u043f\u043e\u0437\u044b \u2014 \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 HWC \u043e\u0442 \u0432\u0445\u043e\u0434\u0430 \u0434\u043e \u0432\u044b\u0445\u043e\u0434\u0430<\/p>\n<\/li>\n<li>\n<p><strong>\u0421\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 workspace<\/strong>\u00a0\u0432\u043c\u0435\u0441\u0442\u043e\u00a0<code>malloc<\/code>\u00a0\u043d\u0430 \u043a\u0430\u0436\u0434\u043e\u043c \u0432\u044b\u0437\u043e\u0432\u0435<\/p>\n<\/li>\n<li>\n<p><strong>Pre-computed position embedding<\/strong>\u00a0\u2014 \u044d\u0442\u043e \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u0430, \u043d\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u043e\u0442 \u0432\u0445\u043e\u0434\u0430<\/p>\n<\/li>\n<li>\n<p><strong>Pre-packed \u0432\u0435\u0441\u0430<\/strong>\u00a0\u2014 \u0442\u0440\u0430\u043d\u0441\u043f\u043e\u0437\u0438\u0446\u0438\u044f \u0438 \u043f\u0430\u043a\u043e\u0432\u043a\u0430 \u043f\u0440\u0438 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0435, \u043d\u0435 \u043f\u0440\u0438 \u0438\u043d\u0444\u0435\u0440\u0435\u043d\u0441\u0435<\/p>\n<\/li>\n<\/ul>\n<h4>\u0425\u0440\u043e\u043d\u043e\u043b\u043e\u0433\u0438\u044f<\/h4>\n<div>\n<div class=\"table\">\n<table>\n<tbody>\n<tr>\n<th>\n<p align=\"left\">\u0424\u0430\u0437\u0430<\/p>\n<\/th>\n<th>\n<p align=\"left\">\u0412\u0440\u0435\u043c\u044f<\/p>\n<\/th>\n<th>\n<p align=\"left\">\u0414\u043b\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u044b<\/p>\n<\/th>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">\u041d\u0430\u0438\u0432\u043d\u044b\u0439 \u043f\u043e\u0440\u0442<\/p>\n<\/td>\n<td>\n<p align=\"left\">24 \u043c\u0441<\/p>\n<\/td>\n<td>\n<p align=\"left\">2 \u043d\u0435\u0434\u0435\u043b\u0438<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">SIMD \u044f\u0434\u0440\u0430<\/p>\n<\/td>\n<td>\n<p align=\"left\">8 \u043c\u0441<\/p>\n<\/td>\n<td>\n<p align=\"left\">3 \u043d\u0435\u0434\u0435\u043b\u0438<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">MatMul + INT8<\/p>\n<\/td>\n<td>\n<p align=\"left\">5 \u043c\u0441<\/p>\n<\/td>\n<td>\n<p align=\"left\">1 \u043c\u0435\u0441\u044f\u0446<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\"><strong>\u0424\u0438\u043d\u0430\u043b\u044c\u043d\u0430\u044f \u043f\u043e\u043b\u0438\u0440\u043e\u0432\u043a\u0430<\/strong><\/p>\n<\/td>\n<td>\n<p align=\"left\">3 \u043c\u0441<\/p>\n<\/td>\n<td>\n<p align=\"left\"><strong>4 \u043c\u0435\u0441\u044f\u0446\u0430<\/strong><\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<blockquote>\n<p>\u041f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0435 2\u043c\u0441 \u0437\u0430\u043d\u044f\u043b\u0438 4 \u043c\u0435\u0441\u044f\u0446\u0430. \u041f\u0435\u0440\u0432\u044b\u0435 16\u043c\u0441 \u2014 2 \u043d\u0435\u0434\u0435\u043b\u0438. \u0412\u043e\u0442 \u0447\u0442\u043e \u0442\u0430\u043a\u043e\u0435 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044f.<\/p>\n<\/blockquote>\n<h3>7 \u0431\u0430\u0433\u043e\u0432 \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u0438<\/h3>\n<p>\u0421\u0430\u043c\u0430\u044f \u0431\u043e\u043b\u0435\u0437\u043d\u0435\u043d\u043d\u0430\u044f \u0447\u0430\u0441\u0442\u044c. Cosine similarity \u0441 ONNX reference \u043d\u0430\u0447\u0438\u043d\u0430\u043b\u0430\u0441\u044c \u043d\u0430\u00a0<strong>0.067<\/strong>\u00a0(\u043c\u0443\u0441\u043e\u0440). \u0414\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c\u00a0<strong>1.0<\/strong>. \u041d\u0430\u0448\u0451\u043b 7 \u0431\u0430\u0433\u043e\u0432 \u0447\u0435\u0440\u0435\u0437 \u043f\u043e\u0441\u043b\u043e\u0439\u043d\u044b\u0435 \u0434\u0430\u043c\u043f\u044b \u2014 \u043a\u0430\u0436\u0434\u044b\u0439 \u0438\u0437 286 \u0442\u0435\u043d\u0437\u043e\u0440\u043e\u0432 \u0441\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u043b\u0441\u044f \u0441 NumPy \u044d\u0442\u0430\u043b\u043e\u043d\u043e\u043c.<\/p>\n<h3>\u0411\u0430\u0433 1: \u0418\u043d\u0434\u0435\u043a\u0441 gamma<\/h3>\n<pre><code>Stage 0, block 2: \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b W(38) \u2014 \u044d\u0442\u043e bias\u041f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e: W(39) \u2014 \u044d\u0442\u043e gamma<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><img style=\"width:87px;height:14px;object-fit:cover;object-position:left;\"\/><\/a><\/div><\/pre>\n<h3>\u0411\u0430\u0433 2: XCA residual connections<\/h3>\n<pre><code>\u0411\u044b\u043b\u043e:   attention_residual = original_input        mlp_residual       = original_input\u041d\u0430\u0434\u043e:   attention_residual = DW_output + pos_embed        mlp_residual       = original_input<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><img style=\"width:14px;height:14px;object-fit:cover;object-position:left;\"\/><\/a><\/div><\/pre>\n<h3>\u0411\u0430\u0433 3: XCA Depthwise Conv \u2014 \u043a\u0430\u0441\u043a\u0430\u0434\u043d\u044b\u0439, \u043d\u0435 \u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u044b\u0439<\/h3>\n<pre><code>\u0411\u044b\u043b\u043e:   conv0(x_split0),  conv1(x_split1)         \u2014 \u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u041d\u0430\u0434\u043e:   r0 = conv0(x_split0),  conv1(r0 + x_split1) \u2014 \u043a\u0430\u0441\u043a\u0430\u0434\u043d\u043e<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><img style=\"width:14px;height:14px;object-fit:cover;object-position:left;\"\/><\/a><\/div><\/pre>\n<h3>\u0411\u0430\u0433 4: Position Embedding \u2014 \u044d\u0442\u043e \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u0430<\/h3>\n<pre><code>\u0411\u044b\u043b\u043e:   pos = Conv1x1(INPUT, W)       \u2014 \u043f\u0435\u0440\u0435\u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0437\u041d\u0430\u0434\u043e:   pos = Conv1x1(CONSTANT, W)    \u2014 \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u0442\u0441\u044f \u043e\u0434\u0438\u043d \u0440\u0430\u0437 \u043f\u0440\u0438 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0435<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><img style=\"width:14px;height:14px;object-fit:cover;object-position:left;\"\/><\/a><\/div><\/pre>\n<h3>\u0411\u0430\u0433 5: XCA Attention \u2014 \u0440\u0430\u0437\u043c\u0435\u0440\u043d\u043e\u0441\u0442\u044c<\/h3>\n<pre><code>\u0411\u044b\u043b\u043e:   attn = softmax(Q @ K^T \/ \u03c4)           \u2014 \u043f\u043e\u043b\u043d\u0430\u044f [C \u00d7 C] \u043c\u0430\u0442\u0440\u0438\u0446\u0430\u041d\u0430\u0434\u043e:   attn_h = softmax(Q_h @ K_h^T \/ \u03c4)     \u2014 per-head [dim \u00d7 dim]<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><img style=\"width:14px;height:14px;object-fit:cover;object-position:left;\"\/><\/a><\/div><\/pre>\n<h3>\u0411\u0430\u0433 6: Workspace overlap<\/h3>\n<pre><code>Stage 3, head_dim=48: attn_buf \u043d\u0430\u0447\u0438\u043d\u0430\u043b\u0441\u044f \u043f\u043e \u0430\u0434\u0440\u0435\u0441\u0443,\u043f\u0435\u0440\u0435\u043a\u0440\u044b\u0432\u0430\u044e\u0449\u0435\u043c\u0443 \u043a\u043e\u043d\u0435\u0446 V_nhd. \u0421\u0434\u0432\u0438\u0433 \u0431\u0443\u0444\u0435\u0440\u0430 \u0440\u0435\u0448\u0438\u043b \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443.<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><img style=\"width:14px;height:14px;object-fit:cover;object-position:left;\"\/><\/a><\/div><\/pre>\n<h3>\u0411\u0430\u0433 7: GELU drift<\/h3>\n<pre><code>tanh-\u0430\u043f\u043f\u0440\u043e\u043a\u0441\u0438\u043c\u0430\u0446\u0438\u044f GELU: \u043e\u0448\u0438\u0431\u043a\u0430 \u03b5 \u043d\u0430 \u043a\u0430\u0436\u0434\u043e\u043c \u0431\u043b\u043e\u043a\u0435.17 \u0431\u043b\u043e\u043a\u043e\u0432 \u00d7 \u03b5 = \u0437\u0430\u043c\u0435\u0442\u043d\u043e\u0435 \u0440\u0430\u0441\u0445\u043e\u0436\u0434\u0435\u043d\u0438\u0435.\u0424\u0438\u043a\u0441: \u0437\u0430\u043c\u0435\u043d\u0438\u043b \u043d\u0430 exact erf (A&amp;S 7.1.26).<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><img style=\"width:14px;height:14px;object-fit:cover;object-position:left;\"\/><\/a><\/div><\/pre>\n<p>\u041a\u0430\u0436\u0434\u044b\u0439 \u0444\u0438\u043a\u0441:\u00a0<strong>+0.1<\/strong>\u00a0cosine similarity \u2192 \u0421\u0435\u043c\u044c \u0444\u0438\u043a\u0441\u043e\u0432:\u00a0<strong>1.000<\/strong><\/p>\n<h3>API<\/h3>\n<pre><code>\/\/ \u0418\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f (~100\u043c\u0441, \u043e\u0434\u0438\u043d \u0440\u0430\u0437)FaceX* fx = facex_init(\"edgeface_xs_fp32.bin\", NULL);\/\/ \u042d\u043c\u0431\u0435\u0434\u0434\u0438\u043d\u0433 (3\u043c\u0441 \u043d\u0430 \u0432\u044b\u0437\u043e\u0432)float face[112 * 112 * 3];  \/\/ RGB, HWC layout, [-1, 1]float embedding[512];facex_embed(fx, face, embedding);\/\/ \u0421\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435 \u0434\u0432\u0443\u0445 \u043b\u0438\u0446float sim = facex_similarity(emb_a, emb_b);\/\/ sim &gt; 0.3 \u2192 \u043e\u0434\u0438\u043d \u0438 \u0442\u043e\u0442 \u0436\u0435 \u0447\u0435\u043b\u043e\u0432\u0435\u043afacex_free(fx);<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><img style=\"width:14px;height:14px;object-fit:cover;object-position:left;\"\/><\/a><\/div><\/pre>\n<p><strong>4 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u00b7 148 \u041a\u0411 \u00b7 \u041d\u043e\u043b\u044c \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0435\u0439 \u00b7 Apache 2.0<\/strong><\/p>\n<h3>\u0412\u044b\u0432\u043e\u0434<\/h3>\n<p>\u041e\u0434\u0438\u043d \u0447\u0435\u043b\u043e\u0432\u0435\u043a \u043c\u043e\u0436\u0435\u0442 \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c inference \u0434\u0432\u0438\u0436\u043e\u043a \u0431\u044b\u0441\u0442\u0440\u0435\u0435 \u043f\u0440\u043e\u0434\u0443\u043a\u0442\u0430 Microsoft \u2014 \u0435\u0441\u043b\u0438 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0438\u0440\u0443\u0435\u0442 \u043f\u043e\u0434 \u043e\u0434\u043d\u0443 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u0443\u044e \u043c\u043e\u0434\u0435\u043b\u044c. ONNX Runtime \u0440\u0430\u0441\u0441\u0447\u0438\u0442\u0430\u043d \u043d\u0430 \u0442\u044b\u0441\u044f\u0447\u0438 \u043c\u043e\u0434\u0435\u043b\u0435\u0439. FaceX \u2014 \u043d\u0430 \u043e\u0434\u043d\u0443.\u00a0<strong>\u0421\u043f\u0435\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0431\u044c\u0451\u0442 \u0443\u043d\u0438\u0432\u0435\u0440\u0441\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u044c.<\/strong><\/p>\n<hr\/>\n<p>\u0418\u0441\u0445\u043e\u0434\u043d\u0438\u043a\u0438:\u00a0<a href=\"https:\/\/github.com\/facex-engine\/facex\" rel=\"noopener noreferrer nofollow\"><strong>github.com\/facex-engine\/facex<\/strong><\/a><\/p>\n<\/div>\n<p>\u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/1029338\/\">https:\/\/habr.com\/ru\/articles\/1029338\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u041f\u043e\u043b\u0433\u043e\u0434\u0430 \u043d\u0430\u0437\u0430\u0434 \u044f \u043d\u0430\u0447\u0430\u043b \u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043d\u0435\u0439\u0440\u043e\u0441\u0435\u0442\u044c EdgeFace-XS \u0438\u0437 ONNX \u0432 \u0447\u0438\u0441\u0442\u044b\u0439 C. \u0414\u0443\u043c\u0430\u043b \u2014 \u0433\u0440\u0430\u0444 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0439, 1.77M \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432, \u0447\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u0439\u0442\u0438 \u043d\u0435 \u0442\u0430\u043a? \u041f\u0435\u0440\u0432\u044b\u0439 \u043d\u0430\u0438\u0432\u043d\u044b\u0439 \u043f\u043e\u0440\u0442 \u0432\u044b\u0434\u0430\u043b\u00a024\u043c\u0441. ONNX Runtime \u2014\u00a03.9\u043c\u0441. \u0412 6 \u0440\u0430\u0437 \u043c\u0435\u0434\u043b\u0435\u043d\u043d\u0435\u0435. \u0410 \u043f\u043e\u0442\u043e\u043c \u043d\u0430\u0447\u0430\u043b\u0430\u0441\u044c \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044f.\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442FaceXONNX Runtime 1.23\u041c\u0435\u0434\u0438\u0430\u043d\u04303.0 \u043c\u04413.9 \u043c\u0441\u041c\u0438\u043d\u0438\u043c\u0443\u043c2.87 \u043c\u04413.18 \u043c\u0441\u0420\u0430\u0437\u043c\u0435\u0440 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438148 \u041a\u041128 \u041c\u0411\u0417\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438\u043d\u0435\u0442Python + onnxruntime\u0422\u043e\u0447\u043d\u043e\u0441\u0442\u044c LFW99.73%99.73%\u0427\u0438\u0441\u0442\u044b\u0439 C \u0441 SIMD \u0438\u043d\u0442\u0440\u0438\u043d\u0441\u0438\u043a\u0430\u043c\u0438 \u043e\u0431\u0433\u043e\u043d\u044f\u0435\u0442 ONNX Runtime \u043d\u0430\u00a023%. \u041e\u0434\u0438\u043d \u0438 \u0442\u043e\u0442 \u0436\u0435 CPU (i5-11500), \u043e\u0434\u043d\u0430 \u043c\u043e\u0434\u0435\u043b\u044c, \u043e\u0434\u043d\u0438 \u0432\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435.\u041f\u0443\u0442\u044c \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438: 24\u043c\u0441 \u2192 3\u043c\u0441\u042d\u0442\u0430\u043f 0: \u041f\u0440\u043e\u0444\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435\u0417\u0430\u043c\u0435\u0440\u0438\u043b \u043a\u0430\u0436\u0434\u0443\u044e \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044e \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e. \u0413\u043b\u0430\u0432\u043d\u044b\u0439 \u0441\u044e\u0440\u043f\u0440\u0438\u0437:\u041c\u0430\u0442\u0440\u0438\u0447\u043d\u043e\u0435 \u0443\u043c\u043d\u043e\u0436\u0435\u043d\u0438\u0435 \u2014 \u0432\u0441\u0435\u0433\u043e 6% \u043e\u0442 \u043e\u0431\u0449\u0435\u0433\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0438\u043d\u0444\u0435\u0440\u0435\u043d\u0441\u0430.\u041d\u0430\u0441\u0442\u043e\u044f\u0449\u0438\u0435 \u0443\u0431\u0438\u0439\u0446\u044b \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438:\u041e\u043f\u0435\u0440\u0430\u0446\u0438\u044f\u0414\u043e\u043b\u044f\u041f\u0440\u043e\u0431\u043b\u0435\u043c\u0430Depthwise conv~30%\u0422\u0440\u0430\u043d\u0441\u043f\u043e\u0437\u044b HWC\u2194CHW \u043d\u0430 \u043a\u0430\u0436\u0434\u043e\u043c \u0431\u043b\u043e\u043a\u0435LayerNorm \u00d7 17~16%\u0421\u043a\u0430\u043b\u044f\u0440\u043d\u044b\u0439 mean\/varianceGELU \u00d7 17~10%\u041d\u0430\u0438\u0432\u043d\u044b\u0439\u00a0tanh()\u00a0\u0447\u0435\u0440\u0435\u0437 math.h\u0422\u0440\u0430\u043d\u0441\u043f\u043e\u0437\u044b \u043f\u0430\u043c\u044f\u0442\u0438~8%\u041b\u0438\u0448\u043d\u0438\u0435 \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044fMatMul~6%\u0423\u0436\u0435 \u0431\u044b\u0441\u0442\u0440\u043e\u042d\u0442\u0430\u043f 1: SIMD \u044f\u0434\u0440\u0430 (24\u043c\u0441 \u2192 8\u043c\u0441)\u041d\u0430\u043f\u0438\u0441\u0430\u043b AVX2 \u0432\u0435\u0440\u0441\u0438\u0438 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438:LayerNorm\u00a0\u2014 fused mean+variance \u0432 \u043e\u0434\u043d\u043e\u043c \u043f\u0440\u043e\u0445\u043e\u0434\u0435. \u0412\u043c\u0435\u0441\u0442\u043e \u0434\u0432\u0443\u0445 \u0446\u0438\u043a\u043b\u043e\u0432 \u043f\u043e \u043f\u0430\u043c\u044f\u0442\u0438 \u2014 \u043e\u0434\u0438\u043d \u0441\u00a0mm256fmadd_ps\u00a0\u0434\u043b\u044f \u043d\u0430\u043a\u043e\u043f\u043b\u0435\u043d\u0438\u044f \u0441\u0443\u043c\u043c\u044b \u0438 \u0441\u0443\u043c\u043c\u044b \u043a\u0432\u0430\u0434\u0440\u0430\u0442\u043e\u0432GELU\u00a0\u2014 \u0432\u044b\u043a\u0438\u043d\u0443\u043b\u00a0tanh(). \u0420\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043b exact erf \u0447\u0435\u0440\u0435\u0437 \u043f\u043e\u043b\u0438\u043d\u043e\u043c\u0438\u0430\u043b\u044c\u043d\u0443\u044e \u0430\u043f\u043f\u0440\u043e\u043a\u0441\u0438\u043c\u0430\u0446\u0438\u044e \u0410\u0431\u0440\u0430\u043c\u043e\u0432\u0438\u0446\u0430-\u0421\u0442\u0435\u0433\u0443\u043d\u0430 (\u0444\u043e\u0440\u043c\u0443\u043b\u0430 7.1.26) \u0441 \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u044b\u043c\u00a0mm256exp_ps\u00a0\u043d\u0430 8 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0437\u0430 \u0442\u0430\u043a\u0442Depthwise conv\u00a0\u2014 \u043f\u0435\u0440\u0435\u0432\u0451\u043b \u0432\u0435\u0441\u044c \u0434\u0432\u0438\u0436\u043e\u043a \u043d\u0430 \u043d\u0430\u0442\u0438\u0432\u043d\u044b\u0439 HWC layout. \u041d\u0438 \u043e\u0434\u043d\u043e\u0433\u043e \u0442\u0440\u0430\u043d\u0441\u043f\u043e\u0437\u0430 \u0432\u043e \u0432\u0441\u0451\u043c forward pass\u042d\u0442\u0430\u043f 2: MatMul (8\u043c\u0441 \u2192 5\u043c\u0441)FP32 packed column-panel: \u0432\u0435\u0441\u0430 \u043f\u0435\u0440\u0435\u043f\u0430\u043a\u043e\u0432\u0430\u043d\u044b \u0432 \u0444\u043e\u0440\u043c\u0430\u0442\u00a0[ceil(N\/8), K, 8]\u00a0\u2014 \u043a\u0430\u0436\u0434\u044b\u0439 \u0441\u0442\u043e\u043b\u0431\u0435\u0446-\u043f\u0430\u043d\u0435\u043b\u044c \u043f\u043e\u043c\u0435\u0449\u0430\u0435\u0442\u0441\u044f \u0432 L1 \u043a\u044d\u0448INT8 GEMM \u043c\u0438\u043a\u0440\u043e\u044f\u0434\u0440\u043e\u00a0\u0441 per-channel \u043a\u0432\u0430\u043d\u0442\u0438\u0437\u0430\u0446\u0438\u0435\u0439:AVX2:\u00a0vpmaddubsw\u00a0\u0441 \u00b163 clamping \u0434\u043b\u044f \u043f\u0440\u0435\u0434\u043e\u0442\u0432\u0440\u0430\u0449\u0435\u043d\u0438\u044f s16 \u043d\u0430\u0441\u044b\u0449\u0435\u043d\u0438\u044fAVX-512 VNNI:\u00a0vpdpbusd\u00a0\u2014 \u043d\u0430\u0442\u0438\u0432\u043d\u044b\u0435 INT8 dot products \u0431\u0435\u0437 \u043d\u0430\u0441\u044b\u0449\u0435\u043d\u0438\u044fThread pool\u00a0\u2014 lock-free \u0441 work-stealing \u0447\u0435\u0440\u0435\u0437 \u0430\u0442\u043e\u043c\u0430\u0440\u043d\u044b\u0439 \u0441\u0447\u0451\u0442\u0447\u0438\u043a \u0438\u00a0WaitOnAddress\/futex\u042d\u0442\u0430\u043f 3: \u041f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0435 \u043c\u0438\u043b\u043b\u0438\u0441\u0435\u043a\u0443\u043d\u0434\u044b (5\u043c\u0441 \u2192 3\u043c\u0441)\u0423\u0431\u0440\u0430\u043b\u00a0\u0432\u0441\u0435\u00a0\u0442\u0440\u0430\u043d\u0441\u043f\u043e\u0437\u044b \u2014 \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 HWC \u043e\u0442 \u0432\u0445\u043e\u0434\u0430 \u0434\u043e \u0432\u044b\u0445\u043e\u0434\u0430\u0421\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 workspace\u00a0\u0432\u043c\u0435\u0441\u0442\u043e\u00a0malloc\u00a0\u043d\u0430 \u043a\u0430\u0436\u0434\u043e\u043c \u0432\u044b\u0437\u043e\u0432\u0435Pre-computed position embedding\u00a0\u2014 \u044d\u0442\u043e \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u0430, \u043d\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u043e\u0442 \u0432\u0445\u043e\u0434\u0430Pre-packed \u0432\u0435\u0441\u0430\u00a0\u2014 \u0442\u0440\u0430\u043d\u0441\u043f\u043e\u0437\u0438\u0446\u0438\u044f \u0438 \u043f\u0430\u043a\u043e\u0432\u043a\u0430 \u043f\u0440\u0438 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0435, \u043d\u0435 \u043f\u0440\u0438 \u0438\u043d\u0444\u0435\u0440\u0435\u043d\u0441\u0435\u0425\u0440\u043e\u043d\u043e\u043b\u043e\u0433\u0438\u044f\u0424\u0430\u0437\u0430\u0412\u0440\u0435\u043c\u044f\u0414\u043b\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u044b\u041d\u0430\u0438\u0432\u043d\u044b\u0439 \u043f\u043e\u0440\u044224 \u043c\u04412 \u043d\u0435\u0434\u0435\u043b\u0438SIMD \u044f\u0434\u0440\u04308 \u043c\u04413 \u043d\u0435\u0434\u0435\u043b\u0438MatMul + INT85 \u043c\u04411 \u043c\u0435\u0441\u044f\u0446\u0424\u0438\u043d\u0430\u043b\u044c\u043d\u0430\u044f \u043f\u043e\u043b\u0438\u0440\u043e\u0432\u043a\u04303 \u043c\u04414 \u043c\u0435\u0441\u044f\u0446\u0430\u041f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0435 2\u043c\u0441 \u0437\u0430\u043d\u044f\u043b\u0438 4 \u043c\u0435\u0441\u044f\u0446\u0430. \u041f\u0435\u0440\u0432\u044b\u0435 16\u043c\u0441 \u2014 2 \u043d\u0435\u0434\u0435\u043b\u0438. \u0412\u043e\u0442 \u0447\u0442\u043e \u0442\u0430\u043a\u043e\u0435 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044f.7 \u0431\u0430\u0433\u043e\u0432 \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u0438\u0421\u0430\u043c\u0430\u044f \u0431\u043e\u043b\u0435\u0437\u043d\u0435\u043d\u043d\u0430\u044f \u0447\u0430\u0441\u0442\u044c. Cosine similarity \u0441 ONNX reference \u043d\u0430\u0447\u0438\u043d\u0430\u043b\u0430\u0441\u044c \u043d\u0430\u00a00.067\u00a0(\u043c\u0443\u0441\u043e\u0440). \u0414\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c\u00a01.0. \u041d\u0430\u0448\u0451\u043b 7 \u0431\u0430\u0433\u043e\u0432 \u0447\u0435\u0440\u0435\u0437 \u043f\u043e\u0441\u043b\u043e\u0439\u043d\u044b\u0435 \u0434\u0430\u043c\u043f\u044b \u2014 \u043a\u0430\u0436\u0434\u044b\u0439 \u0438\u0437 286 \u0442\u0435\u043d\u0437\u043e\u0440\u043e\u0432 \u0441\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u043b\u0441\u044f \u0441 NumPy \u044d\u0442\u0430\u043b\u043e\u043d\u043e\u043c.\u0411\u0430\u0433 1: \u0418\u043d\u0434\u0435\u043a\u0441 gammaStage 0, block 2: \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b W(38) \u2014 \u044d\u0442\u043e bias\u041f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e: W(39) \u2014 \u044d\u0442\u043e gamma\u0411\u0430\u0433 2: XCA residual connections\u0411\u044b\u043b\u043e:   attention_residual = original_input        mlp_residual       = original_input\u041d\u0430\u0434\u043e:   attention_residual = DW_output + pos_embed        mlp_residual       = original_input\u0411\u0430\u0433 3: XCA Depthwise Conv \u2014 \u043a\u0430\u0441\u043a\u0430\u0434\u043d\u044b\u0439, \u043d\u0435 \u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u044b\u0439\u0411\u044b\u043b\u043e:   conv0(x_split0),  conv1(x_split1)         \u2014 \u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u041d\u0430\u0434\u043e:   r0 = conv0(x_split0),  conv1(r0 + x_split1) \u2014 \u043a\u0430\u0441\u043a\u0430\u0434\u043d\u043e\u0411\u0430\u0433 4: Position Embedding \u2014 \u044d\u0442\u043e \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u0430\u0411\u044b\u043b\u043e:   pos = Conv1x1(INPUT, W)       \u2014 \u043f\u0435\u0440\u0435\u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0437\u041d\u0430\u0434\u043e:   pos = Conv1x1(CONSTANT, W)    \u2014 \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u0442\u0441\u044f \u043e\u0434\u0438\u043d \u0440\u0430\u0437 \u043f\u0440\u0438 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0435\u0411\u0430\u0433 5: XCA Attention \u2014 \u0440\u0430\u0437\u043c\u0435\u0440\u043d\u043e\u0441\u0442\u044c\u0411\u044b\u043b\u043e:   attn = softmax(Q @ K^T \/ \u03c4)           \u2014 \u043f\u043e\u043b\u043d\u0430\u044f [C \u00d7 C] \u043c\u0430\u0442\u0440\u0438\u0446\u0430\u041d\u0430\u0434\u043e:   attn_h = softmax(Q_h @ K_h^T \/ \u03c4)     \u2014 per-head [dim \u00d7 dim]\u0411\u0430\u0433 6: Workspace overlapStage 3, head_dim=48: attn_buf \u043d\u0430\u0447\u0438\u043d\u0430\u043b\u0441\u044f \u043f\u043e \u0430\u0434\u0440\u0435\u0441\u0443,\u043f\u0435\u0440\u0435\u043a\u0440\u044b\u0432\u0430\u044e\u0449\u0435\u043c\u0443 \u043a\u043e\u043d\u0435\u0446 V_nhd. \u0421\u0434\u0432\u0438\u0433 \u0431\u0443\u0444\u0435\u0440\u0430 \u0440\u0435\u0448\u0438\u043b \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443.\u0411\u0430\u0433 7: GELU drifttanh-\u0430\u043f\u043f\u0440\u043e\u043a\u0441\u0438\u043c\u0430\u0446\u0438\u044f GELU: \u043e\u0448\u0438\u0431\u043a\u0430 \u03b5 \u043d\u0430 \u043a\u0430\u0436\u0434\u043e\u043c \u0431\u043b\u043e\u043a\u0435.17 \u0431\u043b\u043e\u043a\u043e\u0432 \u00d7 \u03b5 = \u0437\u0430\u043c\u0435\u0442\u043d\u043e\u0435 \u0440\u0430\u0441\u0445\u043e\u0436\u0434\u0435\u043d\u0438\u0435.\u0424\u0438\u043a\u0441: \u0437\u0430\u043c\u0435\u043d\u0438\u043b \u043d\u0430 exact erf (A&amp;S 7.1.26).\u041a\u0430\u0436\u0434\u044b\u0439 \u0444\u0438\u043a\u0441:\u00a0+0.1\u00a0cosine similarity \u2192 \u0421\u0435\u043c\u044c \u0444\u0438\u043a\u0441\u043e\u0432:\u00a01.000API\/\/ \u0418\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f (~100\u043c\u0441, \u043e\u0434\u0438\u043d \u0440\u0430\u0437)FaceX* fx = facex_init(&#171;edgeface_xs_fp32.bin&#187;, NULL);\/\/ \u042d\u043c\u0431\u0435\u0434\u0434\u0438\u043d\u0433 (3\u043c\u0441 \u043d\u0430 \u0432\u044b\u0437\u043e\u0432)float face[112 * 112 * 3];  \/\/ RGB, HWC layout, [-1, 1]float embedding[512];facex_embed(fx, face, embedding);\/\/ \u0421\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435 \u0434\u0432\u0443\u0445 \u043b\u0438\u0446float sim = facex_similarity(emb_a, emb_b);\/\/ sim &gt; 0.3 \u2192 \u043e\u0434\u0438\u043d \u0438 \u0442\u043e\u0442 \u0436\u0435 \u0447\u0435\u043b\u043e\u0432\u0435\u043afacex_free(fx);4 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u00b7 148 \u041a\u0411 \u00b7 \u041d\u043e\u043b\u044c \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0435\u0439 \u00b7 Apache 2.0\u0412\u044b\u0432\u043e\u0434\u041e\u0434\u0438\u043d \u0447\u0435\u043b\u043e\u0432\u0435\u043a \u043c\u043e\u0436\u0435\u0442 \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c inference \u0434\u0432\u0438\u0436\u043e\u043a \u0431\u044b\u0441\u0442\u0440\u0435\u0435 \u043f\u0440\u043e\u0434\u0443\u043a\u0442\u0430 Microsoft \u2014 \u0435\u0441\u043b\u0438 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0438\u0440\u0443\u0435\u0442 \u043f\u043e\u0434 \u043e\u0434\u043d\u0443 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u0443\u044e \u043c\u043e\u0434\u0435\u043b\u044c. ONNX Runtime \u0440\u0430\u0441\u0441\u0447\u0438\u0442\u0430\u043d \u043d\u0430 \u0442\u044b\u0441\u044f\u0447\u0438 \u043c\u043e\u0434\u0435\u043b\u0435\u0439. FaceX \u2014 \u043d\u0430 \u043e\u0434\u043d\u0443.\u00a0\u0421\u043f\u0435\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0431\u044c\u0451\u0442 \u0443\u043d\u0438\u0432\u0435\u0440\u0441\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u044c.\u0418\u0441\u0445\u043e\u0434\u043d\u0438\u043a\u0438:\u00a0github.com\/facex-engine\/facex\u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 https:\/\/habr.com\/ru\/articles\/1029338\/<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-477847","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/477847","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=477847"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/477847\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=477847"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=477847"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=477847"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}