Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hyperparameter optimization with Optuna #24

Merged
merged 11 commits into from
Sep 20, 2024
Merged

Conversation

divijghose
Copy link
Member

Implement Hyperparameter Optimization using Optuna

Description

This pull request introduces hyperparameter optimization capabilities to FastVPINNs using Optuna. The changes allow for efficient, parallelized optimization across multiple GPUs.

New Files

  • fastvpinns/hyperparameter_tuning/optuna_tuner.py
  • fastvpinns/hyperparameter_tuning/objective.py

Key Changes

  1. Added Optuna integration for hyperparameter tuning
  2. Implemented GPU-aware parallelization for optimization trials
  3. Modified main_poisson2d.py to support both YAML config and optimized hyperparameters
  4. Added SQLite storage for Optuna studies to allow resuming interrupted optimizations

Usage

To use the new hyperparameter optimization feature:

  1. Run with YAML config file:
    python main_poisson2d.py input.yaml

  2. Run with hyperparameter optimization:
    python main_poisson2d.py --optimized --n-trials 200 --n-epochs 50000

The --optimized flag triggers the hyperparameter optimization process. The --n-trials argument specifies the number of optimization trials to run. The --n-epochs argument specifies the number of training iterations for each trial.

Dependencies

  • Added SQLAlchemy as a new dependency for Optuna's SQLite storage

GPU Utilization

The optimization process automatically detects available GPUs and distributes trials across them for efficient parallel execution.

Example

On a system with 2 GPUs, running:
python main_poisson2d.py --optimized --n-trials 200

will execute 200 optimization trials, automatically distributed across both GPUs.

Notes

  • The number of parallel jobs is set to the number of available GPUs by default
  • Users can adjust the hyperparameters to be optimized in the objective.py file
  • The optimization results are stored in fastvpinns_optuna.db for persistence

Testing

  • Tested on systems with 1 and 2 GPUs
  • Verified correct distribution of trials across available GPUs
  • Confirmed ability to resume interrupted optimization studies

Future Work

  • Implement visualization of hyperparameter tuning using native Optuna tools.

1. Running with a .yaml config file will lead to usual execution.
2. Running with the --optimized flag will tune hyperparameters with optuna. No input file needed.
1. objective.py defines the objective function for tuning. Contains the fastvpinns object returning metric for tuning.
2. optuna_tuner.py manages the hyperparameter tuning process.
1. Accept number of trials and number of training iteration for each trial as an argument.
1. Accept an is_optimized argument, True if hyperparameter optimization with Optuna is being used.
2. If is_optimized is True, geometry module doesn't print out the test mesh and VTK file for each trial.
3. Backward compatibility - default value of is_optimized is False, existing code with config file should work as is.
1. Creates an SQLite database if it doesn't exist. Can be used for stalled runs or parallel implementation.
2. Lists available number of GPUs and divides jobs.
@divijghose divijghose added the enhancement New feature or request label Sep 18, 2024
Copy link
Collaborator

@thivinanandh thivinanandh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Core Changes : Changes made to the geometry_2d module. A new parameter is added as a new parameter and the default value is set as False.

All checks Passed.

@thivinanandh thivinanandh merged commit a2fa2da into cmgcds:main Sep 20, 2024
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants