Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
RustとPyTorchで作る推論サーバー
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Yudai Hayashi
November 19, 2024
7.7k
12
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
RustとPyTorchで作る推論サーバー
UV Study : Rust LT会で発表した内容になります
https://uniquevision.connpass.com/event/335781/
Yudai Hayashi
November 19, 2024
More Decks by Yudai Hayashi
See All by Yudai Hayashi
技術キャッチアップ効率化を実現する記事推薦システムの構築
yudai00
4
380
Off-Policy Evaluation and Learning for Matching Markets
yudai00
0
160
ジョブマッチングプラットフォームにおける推薦アルゴリズムの活用事例
yudai00
0
180
ユーザーのプロフィールデータを活用した推薦精度向上の取り組み
yudai00
0
780
MCP Clientを活用するための設計と実装上の工夫
yudai00
1
1.4k
人とシゴトのマッチングを実現するための機械学習技術
yudai00
1
130
MCPを理解する
yudai00
18
15k
データバリデーションによるFeature Storeデータ品質の担保
yudai00
1
290
「仮説行動」で学んだ、仮説を深め ていくための方法
yudai00
8
2.1k
Featured
See All Featured
Getting science done with accelerated Python computing platforms
jacobtomlinson
2
450
Speed Design
sergeychernyshev
33
2k
The Invisible Side of Design
smashingmag
301
52k
Navigating the moral maze — ethical principles for Al-driven product design
skipperchong
2
500
Design of three-dimensional binary manipulators for pick-and-place task avoiding obstacles (IECON2024)
konakalab
0
550
YesSQL, Process and Tooling at Scale
rocio
174
15k
The Curse of the Amulet
leimatthew05
2
14k
Dominate Local Search Results - an insider guide to GBP, reviews, and Local SEO
greggifford
PRO
0
310
What does AI have to do with Human Rights?
axbom
PRO
1
2.3k
How Software Deployment tools have changed in the past 20 years
geshan
1
34k
Making the Leap to Tech Lead
cromwellryan
135
10k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
141
35k
Transcript
© 2024 Wantedly, Inc. RustとPyTorchで作る推論サーバー UV Study: Rust LT会 Nov.
19 2024 - Yudai Hayashi
© 2024 Wantedly, Inc. INTERNAL ONLY 自己紹介 林 悠大 • 経歴:
◦ 東京大学工学系研究科でPh.D取得 ◦ 2022年にウォンテッドリーにデータ サイエンティストとして新卒入社。 推薦システムの開発を行う • X: @python_walker • Rust初心者
© 2024 Wantedly, Inc. INTERNAL ONLY なぜデータサイエンティストがRustの話をする?
© 2024 Wantedly, Inc. INTERNAL ONLY PythonコミュニティーにとってのRust 色々なRustで書かれたライブラリやツールが広くPythonで使われるようになってきている https://github.com/pola-rs/polars https://docs.astral.sh/uv/
https://docs.astral.sh/ruff/ • Polars ◦ 構造化データを扱うためのライブラリ • Ruff ◦ linter & code formatter • uv ◦ パッケージマネージャー Rustで書かれた高機能かつ高速なツール がどんどん登場している
© 2024 Wantedly, Inc. INTERNAL ONLY RustとPythonの親和性 RustとPythonは親和性が高い(と自分は思っている) PyO3を使ってpythonでも使える ようなバインディングを生成、
matrurinを使ってbuild→pypiにパ ブリッシュ… みたいなことが簡単にできる RustとPythonを使って機械学習モデルのサービングはどれくらい簡単にできるのだろう?
© 2024 Wantedly, Inc. INTERNAL ONLY 作ったもの Request Response Data
Model file Train Model Serve Model モデルの学習はPython側で行い、モデルを使った推論をRustで行う構成
© 2024 Wantedly, Inc. INTERNAL ONLY 使うライブラリ コードはREADMEから抜粋 • tch-rsを使ってRust側からPyTorchのモデルを利用
• PythonのPyTorchを似たような使用感 • libtorchを入れてパスを通せば使えるようになる ◦ 自分はDockerコンテナ内で “system-wide libtorch” を入れて動かして いたが、Python側で入れたPytorchを利用することもできるらしい
© 2024 Wantedly, Inc. INTERNAL ONLY モデルの学習とtch-rsでの利用 Python側 Rust側 学習したモデルはJITコ
ンパイル テンソルにしてモデルに入力
© 2024 Wantedly, Inc. INTERNAL ONLY モデルの学習とtch-rsでの利用 Python側 Rust側 学習したモデルはJIT
コンパイル 出力は後段で 扱いやすいよ うにベクトル などに変換
© 2024 Wantedly, Inc. INTERNAL ONLY 実験結果 実行環境 レスポンスタイム Rust
(actix-web) 1.75 ms Python (FastAPI) 2.87 ms curl -w “${time_total} ...” で実行時間を計測 Rustのサーバーの方が40 %高速! → 入力データの前処理の部分で差がついた と考えられる パフォーマンス 感じた課題 入力値の前処理では、ちゃんとした変換処 理を書くにはPython側からパラメーター を伝搬させる方法を考える必要がありそう
© 2024 Wantedly, Inc. INTERNAL ONLY まとめ GitHub https://github.com/Hayashi-Yudai/rust-inference-server •
RustでPyTorchのモデルをロードして推論する方法を紹介 • Rustで推論からレスポンスまで返すことで、Pythonで書いた 時よりも40 %の性能改善を実現できる • モデルに入力する前のデータの処理は、現状Rust側では実装 コストが高い部分もありそう