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
68
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の技術発表資料です
AIエージェントのための 隔離された安全なインフラ設計
nearme_tech
PRO
0
22
Claude Code × git worktree で並列開発 (続き) -差分のサービスだけを併設する-
nearme_tech
PRO
1
69
Claude Code × git worktree で並列開発 — サブモジュール構成のリポジトリで成立させる —
nearme_tech
PRO
0
79
LLM + 強化学習
nearme_tech
PRO
0
37
PosthogのA/Bテスト機能の紹介
nearme_tech
PRO
1
110
AIフレンドリーなプロダクトに向けて
nearme_tech
PRO
2
70
初めてのLean言語
nearme_tech
PRO
0
110
Apache Airflow Workflow orchestration without turning cron into spaghetti
nearme_tech
PRO
2
50
実務で役立つ幾何学 ボロノイ図の基礎から グラフ・ネットワーク応用まで
nearme_tech
PRO
1
93
Featured
See All Featured
Understanding Cognitive Biases in Performance Measurement
bluesmoon
32
3.1k
A better future with KSS
kneath
240
18k
HDC tutorial
michielstock
2
960
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.9k
svc-hook: hooking system calls on ARM64 by binary rewriting
retrage
2
630
Organizational Design Perspectives: An Ontology of Organizational Design Elements
kimpetersen
PRO
1
850
Ethics towards AI in product and experience design
skipperchong
2
430
DevOps and Value Stream Thinking: Enabling flow, efficiency and business value
helenjbeal
2
410
Agile Leadership in an Agile Organization
kimpetersen
PRO
0
280
Pawsitive SEO: Lessons from My Dog (and Many Mistakes) on Thriving as a Consultant in the Age of AI
davidcarrasco
0
260
コードの90%をAIが書く世界で何が待っているのか / What awaits us in a world where 90% of the code is written by AI
rkaga
63
46k
Why You Should Never Use an ORM
jnunemaker
PRO
61
10k
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