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で作る強化学習エージェント
Search
NearMeの技術発表資料です
PRO
February 17, 2025
2
170
Rustで作る強化学習エージェント
NearMeの技術発表資料です
PRO
February 17, 2025
Tweet
Share
More Decks by NearMeの技術発表資料です
See All by NearMeの技術発表資料です
Tile38 Overview
nearme_tech
PRO
0
35
Rust 製のコードエディタ “Zed” を使ってみた
nearme_tech
PRO
0
210
実践で使えるtorchのテンソル演算
nearme_tech
PRO
0
21
ローカルLLMを⽤いてコード補完を⾏う VSCode拡張機能を作ってみた
nearme_tech
PRO
0
440
初めてのmarimo (ハンズオン)
nearme_tech
PRO
0
34
ローカルLLM
nearme_tech
PRO
0
55
LlamaIndex Workflow: Build Practical AI Agents Fast
nearme_tech
PRO
0
34
Box-Muller法
nearme_tech
PRO
1
55
Kiro触ってみた
nearme_tech
PRO
0
410
Featured
See All Featured
A better future with KSS
kneath
240
18k
SEOcharity - Dark patterns in SEO and UX: How to avoid them and build a more ethical web
sarafernandez
0
120
StorybookのUI Testing Handbookを読んだ
zakiyama
31
6.6k
What the history of the web can teach us about the future of AI
inesmontani
PRO
1
440
Designing Powerful Visuals for Engaging Learning
tmiket
0
240
The Curse of the Amulet
leimatthew05
1
8.7k
A designer walks into a library…
pauljervisheath
210
24k
コードの90%をAIが書く世界で何が待っているのか / What awaits us in a world where 90% of the code is written by AI
rkaga
60
42k
Speed Design
sergeychernyshev
33
1.5k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
12
1k
Odyssey Design
rkendrick25
PRO
1
500
エンジニアに許された特別な時間の終わり
watany
106
230k
Transcript
0 Rustで作る強化学習エージェント 2024-02-14 第113回NearMe技術勉強会 Takuma KAKINOUE
1 概要 • Rust製のOSS強化学習フレームワークを開発中 ◦ https://github.com/kakky-hacker/reinforcex • 深層学習にはpytorchのrust版であるtchを使⽤ • 今回の勉強会では、reinforcexのサンプルを動かす
2 なぜRustなのか? • メモリ効率性が良い ◦ Pythonだとメモリリークで学習が中断されてしまうことがよくある ◦ Rustだと所有権システムによって使われなくなったメモリが即解放される • 並列処理に強い
◦ 複数エージェントで並列学習するアルゴリズムにおいてPythonより有利に • Rust製の深層学習フレームワークの開発が活発になってきている ◦ https://github.com/huggingface/candle ◦ https://github.com/tracel-ai/burn
3 強化学習アルゴリズム • REINFORCE(実装済) ◦ episodicなアルゴリズム ▪ step単位ではなくepisode単位で学習する ◦ ⽅策ベース
◦ 実装が簡単 • DQN(実装中) ◦ 価値ベース ◦ 実装はやや⼤変 ▪ Replay Buffer ▪ ε-Greedy • その他 ◦ DDPG, TD3, SAC, PPO, A3Cなど追って実装予定
4 サンプルを動かす • rust環境が未構築の場合は以下を実⾏してください ◦ brew install rustup-init ◦ rustup-init
◦ シェルの再起動 • 実験⽤にOpenAI-Gymを使うのでPythonをinstallして以下を実⾏してください ◦ pip3 install gymnasium==0.26.3 • リポジトリ(https://github.com/kakky-hacker/reinforcex)をcloneして、 cargo runを実⾏すればサンプルが動きます
5 インターフェース設計 • サンプルコードを元に解説 ◦ https://github.com/kakky-hacker/reinforcex/blob/master/src/examples/train_c artpole_with_reinforce.rs • 意識したこと ◦
Pythonの強化学習フレームワークであるChainerrlやPFRLと近い設計にした
6 ⼯夫したポイント • NNの重みの初期化メソッドの実装 ◦ https://github.com/kakky-hacker/reinforcex/blob/master/src/misc/weight_ini tializer.rs ◦ ランダム初期化よりもXavierやHeを使うことで学習がちゃんと進むようになった ◦
XavierとHeの使い分けは、該当の層の直後に噛ませる活性化関数の種類による ▪ Xavierの場合、tanhなどと相性が良い ▪ Heの場合、reluなどと相性が良い
7 ⼯夫したポイント • リプレイバッファにおいて、Reference Counterによる変数のライフタイム管理 ◦ https://github.com/kakky-hacker/reinforcex/blob/master/src/replay_buffer/replay_bu ffer.rs ◦ nステップ分の状態遷移を保持するとき、各状態に直前nステップの状態への参照を持たせ
ることで、無駄にメモリを使うことなく保持できる ◦ Reference Counterを使わない場合、nステップ分の状態のコピーが逐⼀保存されるので、 無駄にメモリを使う上に計算コストも増えてしまう
8 今後の展望 • アルゴリズムの拡充 ◦ DQN, PPO, SACなど • tchをcandle(or
burn)に移⾏ • 並列学習周りの実装 • Decision Transformerの実装 スター付けてもらえると、やる気が出ます! https://github.com/kakky-hacker/reinforcex
9 Thank you