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
ハイパーパラメータ最適化フレームワーク Optunaの最新機能紹介 - 2023/10/28 ...
Search
Preferred Networks
PRO
October 27, 2023
Technology
2
2k
ハイパーパラメータ最適化フレームワーク Optunaの最新機能紹介 - 2023/10/28 PyCon APAC 2023
Optunaの最新リリースv3.4で導入された新機能について紹介いたします。
イベントサイト:
https://2023-apac.pycon.jp/
Preferred Networks
PRO
October 27, 2023
Tweet
Share
More Decks by Preferred Networks
See All by Preferred Networks
Kubernetes における cgroup v2 でのOut-Of-Memory 問題の解決
pfn
PRO
0
450
Preferred Networks (PFN) とLLM Post-Training チームの紹介 / 第4回 関東Kaggler会 スポンサーセッション
pfn
PRO
1
310
AIベンダーにおけるAIセキュリティ・ガバナンスへの取組
pfn
PRO
1
93
オフィス環境及び機械学習向けKubernetesクラスタでのAkamai SIA(DNS ファイアウォール)活用事例
pfn
PRO
0
96
Deploying PLaMo 2 with vLLM: A Practical Guide / vLLM roundup Community Meetup Tokyo
pfn
PRO
1
470
New Cache Hierarchy for Container Images and OCI Artifacts in Kubernetes Clusters using Containerd / KubeCon + CloudNativeCon Japan
pfn
PRO
0
280
Preferred Networks金融チームのご紹介
pfn
PRO
4
2k
KubeCon + CloudNativeCon Europe 2025 Recap: The GPUs on the Bus Go 'Round and 'Round / Kubernetes Meetup Tokyo #70
pfn
PRO
0
310
LLMの開発と社会実装の今と未来 / AI Builders' Community (ABC) vol.2
pfn
PRO
3
740
Other Decks in Technology
See All in Technology
LLM翻訳ツールの開発と海外のお客様対応等への社内導入事例
gree_tech
PRO
0
440
JuniorからSeniorまで: DevOpsエンジニアの成長ロードマップ
yuriemori
2
350
衝突して強くなる! BLUE GIANTと アジャイルチームの共通点とは ― いきいきと活気に満ちたグルーヴあるチームを作るコツ ― / BLUE GIANT and Agile Teams
naitosatoshi
0
290
実運用で考える PGO
kworkdev
PRO
0
130
スプリントレトロスペクティブはチーム観察の宝庫? 〜チームの衝突レベルに合わせたアプローチ仮説!〜
electricsatie
1
150
【 LLMエンジニアがヒューマノイド開発に挑んでみた 】 - 第104回 Machine Learning 15minutes! Hybrid
soneo1127
0
250
【5分でわかる】セーフィー エンジニア向け会社紹介
safie_recruit
0
30k
ZOZOマッチのアーキテクチャと技術構成
zozotech
PRO
2
1.2k
MCPで変わる Amebaデザインシステム「Spindle」の開発
spindle
PRO
3
2.2k
「魔法少女まどか☆マギカ Magia Exedra」のグローバル展開を支える、開発チームと翻訳チームの「意識しない協創」を実現するローカライズシステム
gree_tech
PRO
0
440
退屈なことはDevinにやらせよう〜〜Devin APIを使ったVisual Regression Testの自動追加〜
kawamataryo
4
1.1k
大「個人開発サービス」時代に僕たちはどう生きるか
sotarok
12
5.7k
Featured
See All Featured
Measuring & Analyzing Core Web Vitals
bluesmoon
9
570
Learning to Love Humans: Emotional Interface Design
aarron
273
40k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
8
910
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
36
2.5k
Writing Fast Ruby
sferik
628
62k
Into the Great Unknown - MozCon
thekraken
40
2k
Statistics for Hackers
jakevdp
799
220k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
333
22k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
656
61k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
507
140k
VelocityConf: Rendering Performance Case Studies
addyosmani
332
24k
GraphQLとの向き合い方2022年版
quramy
49
14k
Transcript
ハイパーパラメータ最適化フレームワーク Optunaの最新機能紹介 Masashi Shibata PyCon APAC 2023 in Tokyo, Japan
2023.10.27-2023.10.28
MASASHI SHIBATA Preferred Networks, Inc. Release Manager of Optuna 3.3
and 3.4 Creator of Optuna Dashboard GitHub @c-bata / X @c_bata_
3 Optuna 3.4がリリースされました! https://x.com/OptunaAutoML/status/1714181590354739605
4 本発表の内容 1 Optuna / Optuna Dashboardの概要と基本的な使い方 2 Optuna Artifactを使った実験管理
3 Preferential Optimizationと生成AIへの活用 4 Jupyter Lab拡張とVS Code拡張
5 Optunaの概要と基本的な使い方
6 Optunaとは? ハイパラ最適化を表す絵 機械学習のハイパー パラメータ最適化 自律移動ロボット 3D CAD (Tunny) ※1
$ pip install optuna ハイパーパラメータ最適化フレームワーク ※1 詳細は下記Optuna公式ブログ記事を参照 https://medium.com/optuna/black-box-optimization-of-geometry-and-functionality-by-integrating-optuna-and-3d-cad-f2d2984d263e
7 Optunaの基本的な使い方 1 目的関数を定義 2 サジェストAPI経由でハイパー パラメータをサンプル 3 最適化の状態を管理する Studyオブジェクトを作成
4 試行回数を指定して最適化開始 5 結果の表示 import optuna def objective(trial: optuna.Trial) -> float: x1 = trial.suggest_float("x1", -10, 10) x2 = trial.suggest_float("x2", -10, 10) return (x1 - 2)**2 + (x2 + 5)**2 study = optuna.create_study( storage="sqlite:///db.sqlite3", study_name="optimize-quadratic-function" ) study.optimize(objective, n_trials=100) print(f"Best value: {study.best_value}") print(f"Best params: {study.best_params}")
8 Optunaの基本的な使い方 1 目的関数を定義 2 サジェストAPI経由でハイパー パラメータをサンプル 3 最適化の状態を管理する Studyオブジェクトを作成
4 試行回数を指定して最適化開始 5 結果の表示 import optuna def objective(trial: optuna.Trial) -> float: x1 = trial.suggest_float("x1", -10, 10) x2 = trial.suggest_float("x2", -10, 10) return (x1 - 2)**2 + (x2 + 5)**2 study = optuna.create_study( storage="sqlite:///db.sqlite3" study_name="optimize-quadratic-function" ) study.optimize(objective, n_trials=100) print(f"Best value: {study.best_value}") print(f"Best params: {study.best_params}") Trialオブジェクトを受け取り 評価値(float)を返す関数を定義
9 Optunaの基本的な使い方 1 目的関数を定義 2 サジェストAPI経由でハイパー パラメータをサンプル 3 最適化の状態を管理する Studyオブジェクトを作成
4 試行回数を指定して最適化開始 5 結果の表示 import optuna def objective(trial: optuna.Trial) -> float: x1 = trial.suggest_float("x1", -10, 10) x2 = trial.suggest_float("x2", -10, 10) return (x1 - 2)**2 + (x2 + 5)**2 study = optuna.create_study( storage="sqlite:///db.sqlite3" study_name="optimize-quadratic-function" ) study.optimize(objective, n_trials=100) print(f"Best value: {study.best_value}") print(f"Best params: {study.best_params}") ※この最小化問題の解は (x1, x2) = (2, -5)
10 Optunaの基本的な使い方 1 目的関数を定義 2 サジェストAPI経由でハイパー パラメータをサンプル 3 最適化の状態を管理する Studyオブジェクトを作成
4 試行回数を指定して最適化開始 5 結果の表示 import optuna def objective(trial: optuna.Trial) -> float: x1 = trial.suggest_float("x1", -10, 10) x2 = trial.suggest_float("x2", -10, 10) return (x1 - 2)**2 + (x2 + 5)**2 study = optuna.create_study( storage="sqlite:///db.sqlite3" study_name="optimize-quadratic-function" ) study.optimize(objective, n_trials=100) print(f"Best value: {study.best_value}") print(f"Best params: {study.best_params}") x1 および x2 の探索空間を定義 今回はどちらも区間 [-10, 10] の中で探索
11 Optunaの基本的な使い方 1 目的関数を定義 2 サジェストAPI経由でハイパー パラメータをサンプル 3 最適化の状態を管理する Studyオブジェクトを作成
4 試行回数を指定して最適化開始 5 結果の表示 import optuna def objective(trial: optuna.Trial) -> float: x1 = trial.suggest_float("x1", -10, 10) x2 = trial.suggest_float("x2", -10, 10) return (x1 - 2)**2 + (x2 + 5)**2 study = optuna.create_study( storage="sqlite:///db.sqlite3", study_name="optimize-quadratic-function" ) study.optimize(objective, n_trials=100) print(f"Best value: {study.best_value}") print(f"Best params: {study.best_params}") 最適化履歴をデータベースに保存
12 Optunaの基本的な使い方 1 目的関数を定義 2 サジェストAPI経由でハイパー パラメータをサンプル 3 最適化の状態を管理する Studyオブジェクトを作成
4 試行回数を指定して最適化開始 5 結果の表示 import optuna def objective(trial: optuna.Trial) -> float: x1 = trial.suggest_float("x1", -10, 10) x2 = trial.suggest_float("x2", -10, 10) return (x1 - 2)**2 + (x2 + 5)**2 study = optuna.create_study( storage="sqlite:///db.sqlite3" study_name="optimize-quadratic-function" ) study.optimize(objective, n_trials=100) print(f"Best value: {study.best_value}") print(f"Best params: {study.best_params}") 目的関数を100回呼び出し
13 Optunaの基本的な使い方 1 目的関数を定義 2 サジェストAPI経由でハイパー パラメータをサンプル 3 最適化の状態を管理する Studyオブジェクトを作成
4 試行回数を指定して最適化開始 5 結果の表示 import optuna def objective(trial: optuna.Trial) -> float: x1 = trial.suggest_float("x1", -10, 10) x2 = trial.suggest_float("x2", -10, 10) return (x1 - 2)**2 + (x2 + 5)**2 study = optuna.create_study( storage="sqlite:///db.sqlite3" study_name="optimize-quadratic-function" ) study.optimize(objective, n_trials=100) print(f"Best value: {study.best_value}") print(f"Best params: {study.best_params}")
14 Optunaの基本的な使い方 1 目的関数を定義 2 サジェストAPI経由でハイパー パラメーターをサンプル 3 最適化の状態を管理する Studyオブジェクトを作成
4 試行回数を指定して最適化開始 5 結果の表示 import optuna def objective(trial: optuna.Trial) -> float: # ハイパーパラメーターのサンプル x1 = trial.suggest_float("x1", -10, 10) x2 = trial.suggest_float("x2", -10, 10) # 評価値を計算してリターン return (x1 - 1)**2 + (x2 + 5)**2 study = optuna.create_study() study.optimize(objective, n_trials=100) print(f"Best value: {study.best_value}") print(f"Best params: {study.best_params}") $ python example.py Trial 0 finished with value: 83.8192 and parameters: {'x1': -8.1549, 'x2': -5.0722} Trial 1 finished with value: 9.3275 and parameters: {'x1': -1.7273, 'x2': -3.6254} Trial 2 finished with value: 79.0848 and parameters: {'x1': 9.8671, 'x2': -4.3235} Trial 3 finished with value: 56.8358 and parameters: {'x1': -4.2930, 'x2': 0.3683} Trial 4 finished with value: 198.6490 and parameters: {'x1': -4.0875, 'x2': 8.1440} ... Best value: 0.02332568173253747 Best params: {'x1': 2.0699302180632904, 'x2': -4.864222806281179} 実行結果
15 Optunaの基本的な使い方 1 目的関数を定義 2 サジェストAPI経由でハイパー パラメーターをサンプル 3 最適化の状態を管理する Studyオブジェクトを作成
4 試行回数を指定して最適化開始 5 結果の表示 import optuna def objective(trial: optuna.Trial) -> float: # ハイパーパラメーターのサンプル x1 = trial.suggest_float("x1", -10, 10) x2 = trial.suggest_float("x2", -10, 10) # 評価値を計算してリターン return (x1 - 1)**2 + (x2 + 5)**2 study = optuna.create_study() study.optimize(objective, n_trials=100) print(f"Best value: {study.best_value}") print(f"Best params: {study.best_params}") Optuna Dashboardによる履歴の確認 $ pip install optuna-dashboard $ optuna-dashboard sqlite:///db.sqlite3
16 より詳細な使い方は書籍をチェック! 初学者にとって最適な一冊です • 丁寧なチュートリアル • 様々な便利機能の紹介 • 様々な応用事例の紹介 •
アルゴリズムの詳細 好評発売中です!
17 最新機能紹介 ① Optuna Artifact を使った 実験管理
18 Artifactによるファイル管理 学習済みモデルや画像など大きな データもOptunaで管理が可能に! Optuna Artifactを使った実験管理 import optuna from optuna.artifacts
import FileSystemArtifactStore from optuna.artifacts import upload_artifact # この例では ./artifacts ディレクトリ以下に生成物を保存 artifact_store = FileSystemArtifactStore("./artifacts") def objective(trial: optuna.Trial) -> float: param = trial.suggest_float(...) file_path = generate_image(param, ...) # 生成物のアップロード (e.g. 学習済みモデル等) upload_artifact(trial, file_path, artifact_store) return ... 画像をArtifact Storeにアップロード ※ AWS S3やGoogle Cloud Storageにも対応
19 Optuna Dashboardでの確認 $ optuna-dashboard sqlite:///db.sqlite3 \ --artifact-dir ./artifacts コマンドラインでの起動方法
Python APIでの起動方法 AWS S3等にアップロードしたファイル を閲覧するにはPython APIを使用 from optuna.storages import RDBStorage from optuna.artifacts import Boto3ArtifactStore from optuna_dashboard import run_server storage = RDBStorage("sqlite:///db.sqlite3") artifact_store = Boto3ArtifactStore("my-bucket") run_server(storage, artifact_store=artifact_store)
20 Optuna Dashboardでの確認 $ optuna-dashboard sqlite:///db.sqlite3 \ --artifact-dir ./artifacts Optuna
Dashboardの起動方法 コマンドラインオプションの使用 Python APIでの起動方法 AWS S3等にアップロードしたファイル を閲覧するにはPython APIを使用 from optuna.storages import RDBStorage from optuna.artifacts import Boto3ArtifactStore from optuna_dashboard import run_server storage = RDBStorage("sqlite:///db.sqlite3") artifact_store = Boto3ArtifactStore("my-bucket") run_server(storage, artifact_store=artifact_store) 様々なファイル形式に対応! 3Dモデル 分子構造 音声
21 最新機能紹介 ② Preferential Optimization と生成AIへの活用
22 音声合成 生成AIにおけるハイパーパラメータ最適化 定量的に評価値を計算できず、人間による確認(主観評価)が重要 画像生成 自然言語生成 Optuna Dashboard はPythonのハイパー パラメーター最適化フ
レームワークです。。。
23 Preferential Optimization チュートリアル
24 お題:かわいいOptunaくんの生成 (Stable Diffusion) Hey! Please make me cuter 🙏
Optunaくん Sure. Let’s try using Stable Diffusion! Me
25 お題:かわいいOptunaくんの生成 (Stable Diffusion) 入力画像 Stable Diffusion プロンプト a mascot
character with two eyes and a mouth, smiling, charming, painting huggingface.co/stabilityai/ stable-diffusion-2-1 ? ナンカチガウ... 出力画像
26 お題:かわいいOptunaくんの生成 (Stable Diffusion) Hmm… 😫 Let me optimize a
prompt with Optuna. Optunaくん But wait… How am I supposed to score how cute I am? 🤔 It’s time to use Preferential Optimization! Me
27 Preferential Optimization による相対評価 2つのプログラムが協調的に動作しながら最適化を進める
28 Optuna Dashboardの操作画面 I prefer A over B! I prefer
B over A!
29 新 Optunaくん チュートリアルのお題:画像生成(img2img) 旧 Optunaくん Cool! The left one
is exactly I wanted 🥰 Me These images generated!
30 Preferential Optimizationのコード解説 generator.py ソースコードURL👇 https://gist.github.com/c-bata/449f2e90ac50a1285b7fe210ab51eae6 これから解説するコード Database & File
Storage Optuna Storage sqlite:///db.sqlite3 Artifact Store FileSystemBackend Optuna Dashboard 1. Studyの作成 2. 画面に表示するArtifactの指定 3. 新しいTrialの生成 4. パラメーターのサンプル 5. Stable Diffusionモデル実行 6. 画像アップロード 7. 以降、Step 3-6を繰り返す Optuna Dashboardの起動 $ optuna-dashboard …
31 公式チュートリアルもチェック! https://optuna-dashboard.readthedocs.io/en/latest /tutorials/preferential-optimization.html 夕焼け色(オレンジ色)のRGBカラーコードをOptunaで探索するチュートリアル
32 最新機能紹介 ③ Jupyter Lab拡張 VS Code拡張
33 $ pip install jupyterlab jupyterlab-optuna
34 Visual Studio Marketplace からインストール!
35 まとめ
36 本発表で話したこと • Optunaの基本的な使い方 • Artifact機能を使った実験管理 • Preferential Optimizationと生成AIへの活用 •
VS Code拡張やJupyter Lab拡張の紹介 最後におねがい • Optunaをみなさまのプロジェクトでご活用ください!気に入った方はGithub Starsもぜひおねがいします。 • Preferential OptimizationやArtifactなど最新機能の活用事例を ぜひブログやSNSでシェアしてください! おわりに
Making the real world computable