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
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Preferred Networks
PRO
October 27, 2023
Technology
2.2k
3
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
ハイパーパラメータ最適化フレームワーク Optunaの最新機能紹介 - 2023/10/28 PyCon APAC 2023
Optunaの最新リリースv3.4で導入された新機能について紹介いたします。
イベントサイト:
https://2023-apac.pycon.jp/
Preferred Networks
PRO
October 27, 2023
More Decks by Preferred Networks
See All by Preferred Networks
User Namespaces in Production: Enabling Root in Containers with RWX
pfn
PRO
0
18
PLaMo 3.0 Primeの事後学習
pfn
PRO
0
270
PLaMo 3.0 Primeの構造化出力サポート
pfn
PRO
0
180
plamo-3-translateの開発
pfn
PRO
0
270
PLaMoを毎日の開発で使い育てていく
pfn
PRO
0
180
The Making of AI Chips
pfn
PRO
1
1k
国産生成AI PLaMoを支える事後学習と推論最適化
pfn
PRO
13
5.5k
Japanese SimpleQA: 日本語における事実に基づいた回答能力の評価ベンチマーク
pfn
PRO
1
430
Headlampと独自プラグインを活用したKubernetesダッシュボードの機能拡張
pfn
PRO
2
460
Other Decks in Technology
See All in Technology
名古屋の市バスGTFS-JPデータ×スガキヤ 最寄りバス停検索をAmazon ElastiCache Serverless for Valkeyで最適化する
usanchuu
1
260
Issue設計から始める仕様駆動開発 / 20260731 Mizuki Hirata
shift_evolve
PRO
1
130
個人OSSが、机の上から世界に広がるまでの話
shinyasaita
1
340
初めてのGitHub Actions / GitHub Actions at First
tooppoo
0
140
AIは実装を速くする。では、私たちは何を今作るべきか?-立場を越えてリリースに向き合ったチーム開発の実践 / 20260801 Hiromi Nakaya and Naoki Takahashi
shift_evolve
PRO
3
370
第3回しろおびセキュリティスポンサーセッション
log0417
0
140
制約理論(ToC)入門 2026版
recruitengineers
PRO
2
290
Sansan Engineering Unit 紹介資料
sansan33
PRO
1
4.9k
『三匹の子ぶた』から学ぶネットワークセキュリティの昔と今 / Network Security: Then and Now Through the Lens of The Three Little Pigs
nttcom
1
1.6k
【5分でわかる】セーフィー エンジニア向け会社紹介
safie_recruit
0
53k
取引先から届く 「セキュリティチェックシート」の読み解き方
kamadamakoto
0
110
【CEDEC2026】『Relink』を拡張せよ - 『GRANBLUE FANTASY: Relink - Endless Ragnarok』の開発速度と品質を守るCI運用
cygames
PRO
0
110
Featured
See All Featured
Code Review Best Practice
trishagee
74
20k
For a Future-Friendly Web
brad_frost
183
10k
The #1 spot is gone: here's how to win anyway
tamaranovitovic
3
1.1k
Impact Scores and Hybrid Strategies: The future of link building
tamaranovitovic
0
360
The Spectacular Lies of Maps
axbom
PRO
1
890
コードの90%をAIが書く世界で何が待っているのか / What awaits us in a world where 90% of the code is written by AI
rkaga
63
45k
Documentation Writing (for coders)
carmenintech
77
5.4k
The Language of Interfaces
destraynor
162
27k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
32
4.1k
Marketing Yourself as an Engineer | Alaka | Gurzu
gurzu
0
270
brightonSEO & MeasureFest 2025 - Christian Goodrich - Winning strategies for Black Friday CRO & PPC
cargoodrich
3
760
Data-driven link building: lessons from a $708K investment (BrightonSEO talk)
szymonslowik
1
1.2k
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