Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
RustでDeepQNetworkを実装する
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
NearMeの技術発表資料です
PRO
March 21, 2025
67
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
RustでDeepQNetworkを実装する
Rustで強化学習アルゴリズムをフルスクラッチで実装します。
ニューラルネット部分はtch-rsを用いています。
NearMeの技術発表資料です
PRO
March 21, 2025
More Decks by NearMeの技術発表資料です
See All by NearMeの技術発表資料です
Claude Code × git worktree で並列開発 (続き) -差分のサービスだけを併設する-
nearme_tech
PRO
1
56
Claude Code × git worktree で並列開発 — サブモジュール構成のリポジトリで成立させる —
nearme_tech
PRO
0
71
LLM + 強化学習
nearme_tech
PRO
0
33
PosthogのA/Bテスト機能の紹介
nearme_tech
PRO
1
74
AIフレンドリーなプロダクトに向けて
nearme_tech
PRO
2
65
初めてのLean言語
nearme_tech
PRO
0
110
Apache Airflow Workflow orchestration without turning cron into spaghetti
nearme_tech
PRO
2
39
実務で役立つ幾何学 ボロノイ図の基礎から グラフ・ネットワーク応用まで
nearme_tech
PRO
1
77
SQL/ID抽出タスクから考える 実践的なハルシネーション対策
nearme_tech
PRO
1
90
Featured
See All Featured
The Limits of Empathy - UXLibs8
cassininazir
1
680
コードの90%をAIが書く世界で何が待っているのか / What awaits us in a world where 90% of the code is written by AI
rkaga
63
46k
Money Talks: Using Revenue to Get Sh*t Done
nikkihalliwell
0
500
Jess Joyce - The Pitfalls of Following Frameworks
techseoconnect
PRO
1
410
Writing Fast Ruby
sferik
630
63k
Leveraging LLMs for student feedback in introductory data science courses - posit::conf(2025)
minecr
1
400
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
38
3k
Claude Code どこまでも/ Claude Code Everywhere
nwiizo
67
58k
Self-Hosted WebAssembly Runtime for Runtime-Neutral Checkpoint/Restore in Edge–Cloud Continuum
chikuwait
0
810
How to build an LLM SEO readiness audit: a practical framework
nmsamuel
1
910
The MySQL Ecosystem @ GitHub 2015
samlambert
251
13k
Getting science done with accelerated Python computing platforms
jacobtomlinson
2
480
Transcript
0 2025-03-21 第116回NearMe技術勉強会 Takuma KAKINOUE RustでDeepQNetworkを実装する (おまけ)tch-rsからcandleに移⾏した結果
1 はじめに • 今回のスライドは、Zennにアップロードした記事(以下、url)のダイジェストになり ます ◦ https://zenn.dev/kakky_hacker/articles/652bd7f9a1e6c1
2 API解説 • DQNのインターフェース ◦ actメソッド ▪ 推論時に毎ステップ呼ぶ ◦ act_and_trainメソッド
▪ 訓練時に毎ステップ呼ぶ
3 actメソッドの実装 • 推論時に呼ばれる想定なので、tch::no_gradで勾配計算を無効化 • あとは、Qネットワークが出⼒したQ値の最⼤値のindexを返しているだけ
4 act_and_trainメソッドの実装 • コードは⻑いので貼れないが、やっていることは以下。 ◦ 観測した状態に対して、最⼤Q値の⾏動を算出する ◦ 最⼤Q値の⾏動を選択するかランダム⾏動を選択するかを決める(ε-greedy法など) ◦ リプレイバッファに状態‧⾏動‧報酬を記録する
◦ update間隔に達していたら、 _updateメソッド(次スライドで解説)で重みを更新する ◦ 選択した⾏動を返す
5 _updateメソッドの実装 • ⼤まかな流れ ◦ リプレイバッファから経験をサンプリング ◦ Q値の更新式の各変数の値を求める ◦ 損失を計算して、重みを更新する
• Q値の更新式は以下
6 _updateメソッドの実装 • 損失の計算式 ◦ 現状は平均⼆乗誤差を使っているが、Huber損失も実装予定 ▪ Huber損失 • https://ja.wikipedia.org/wiki/Huber%E6%90%8D%E5%A4%B1
7 tch-rsとcandle • tch-rs(https://github.com/LaurentMazare/tch-rs) ◦ メリット ▪ コアの部分がPytorchなので実績と信頼性は⼗分 ◦ デメリット
▪ Pytorchの全機能をRustから呼べるわけではない ▪ しかし、全機能を含んだコア部分をinstallするので重くなりがち • candle(https://github.com/huggingface/candle) ◦ メリット ▪ Pure Rustなので、Rustから使う場合は型推論周りは良い ▪ パッケージが軽い、WebAssenbly対応 ◦ デメリット ▪ Pytorchと⽐べてまだ実績が少ない
8 tch-rsからcandle移⾏した結果 • packageの容量を1.7GB → 0.8GBに削減できた! • しかし、訓練時のメモリ使⽤量や実⾏時間はtch-rsの⽅が若⼲性能が良かった ◦ 結局、しばらくはtch-rsで開発を進めることに
9 今後の展望 • [WIP] Proximal Policy Optimizationの実装 ◦ PPO論⽂:https://arxiv.org/abs/1707.06347 •
Soft Actor Criticの実装 ◦ SAC論⽂:https://arxiv.org/abs/1801.01290 • リプレイバッファから経験をサンプリングするときに優先度を設ける ◦ Prioritized Replay Buffer論⽂:https://arxiv.org/abs/1511.05952 • 好奇⼼報酬による探索の効率化の導⼊ ◦ RND論⽂:https://arxiv.org/abs/1810.12894 ◦ SND論⽂:https://arxiv.org/abs/2302.11563
10 Thank you