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
AIベンダーにおけるAIセキュリティ・ガバナンスへの取組
pfn
PRO
1
52
オフィス環境及び機械学習向けKubernetesクラスタでのAkamai SIA(DNS ファイアウォール)活用事例
pfn
PRO
0
72
Deploying PLaMo 2 with vLLM: A Practical Guide / vLLM roundup Community Meetup Tokyo
pfn
PRO
1
430
New Cache Hierarchy for Container Images and OCI Artifacts in Kubernetes Clusters using Containerd / KubeCon + CloudNativeCon Japan
pfn
PRO
0
260
Preferred Networks金融チームのご紹介
pfn
PRO
3
1.9k
KubeCon + CloudNativeCon Europe 2025 Recap: The GPUs on the Bus Go 'Round and 'Round / Kubernetes Meetup Tokyo #70
pfn
PRO
0
300
LLMの開発と社会実装の今と未来 / AI Builders' Community (ABC) vol.2
pfn
PRO
3
710
PFN Company Deck
pfn
PRO
1
6.4k
EDRからERM: PFN-SIRTが関わるセキュリティとリスクへの取り組み
pfn
PRO
2
500
Other Decks in Technology
See All in Technology
Claude Codeから我々が学ぶべきこと
oikon48
10
2.8k
意志の力が9割。アニメから学ぶAI時代のこれから。
endohizumi
1
100
Instant Apps Eulogy
cyrilmottier
1
120
Telemetry APIから学ぶGoogle Cloud ObservabilityとOpenTelemetryの現在 / getting-started-telemetry-api-with-google-cloud
k6s4i53rx
0
160
リモートワークで心掛けていること 〜AI活用編〜
naoki85
0
180
AIに目を奪われすぎて、周りの困っている人間が見えなくなっていませんか?
cap120
1
690
Google Agentspaceを実際に導入した効果と今後の展望
mixi_engineers
PRO
3
760
Amazon Inspector コードセキュリティで手軽に実現するシフトレフト
maimyyym
0
130
アカデミーキャンプ 2025 SuuuuuuMMeR「燃えろ!!ロボコン」 / Academy Camp 2025 SuuuuuuMMeR "Burn the Spirit, Robocon!!" DAY 1
ks91
PRO
0
150
Exadata Database Service on Dedicated Infrastructure セキュリティ、ネットワーク、および管理について
oracle4engineer
PRO
0
290
Backlog AI アシスタントが切り開く未来
vvatanabe
1
160
【新卒研修資料】数理最適化 / Mathematical Optimization
brainpadpr
29
13k
Featured
See All Featured
What’s in a name? Adding method to the madness
productmarketing
PRO
23
3.6k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
10
1k
Stop Working from a Prison Cell
hatefulcrawdad
271
21k
Music & Morning Musume
bryan
46
6.7k
The Power of CSS Pseudo Elements
geoffreycrofte
77
5.9k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
32
1.3k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
8
880
Why You Should Never Use an ORM
jnunemaker
PRO
58
9.5k
Building Better People: How to give real-time feedback that sticks.
wjessup
367
19k
The Invisible Side of Design
smashingmag
301
51k
Git: the NoSQL Database
bkeepers
PRO
431
65k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
23
1.4k
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