Skip to content

Add Trackio Integration for Optuna #259

Merged
c-bata merged 26 commits intooptuna:mainfrom
ParagEkbote:add-trackio-integration
Jan 16, 2026
Merged

Add Trackio Integration for Optuna #259
c-bata merged 26 commits intooptuna:mainfrom
ParagEkbote:add-trackio-integration

Conversation

@ParagEkbote
Copy link
Copy Markdown
Contributor

@ParagEkbote ParagEkbote commented Dec 18, 2025

Fixes #248

Motivation

As described in the issue, this PR implements an TrackioCallback for optuna-integration. Currently, trackio has a min python version of 3.10 and since python 3.9 has reached EOL, we will be required to bump the min. version in this repo to ensure that CI will be green.

Description of the changes

The implementation of the callback is similar to the wandb callback, as the library is designed to be an open-source and offline alternative to wandb. The main difference between the wandb and trackio is that trackio does not rely on a global mutable state, each run is explicitly created and each run has a fixed lifetime. The API docs have also helped to define the scope of the callback.

The runs can be visualized as follows:

image

We can also display the results as an HF Space and an dataset. The example is as follows:

import optuna
import trackio

from optuna_integration.trackio import TrackioCallback


def main():
    callback = TrackioCallback(
        project="toy-optuna-trackio-multirun",
        metric_name="loss",
        as_multirun=True,
        resume="allow",


        dataset_id="AINovice2005/toy-optuna-hpo-dataset",
        space_id="AINovice2005/optuna-dashboard",
        private=False,  # set True if you want private
    )

    @callback.track_in_trackio()
    def objective(trial: optuna.trial.Trial) -> float:
        x = trial.suggest_float("x", -10.0, 10.0)
        loss = (x - 2.0) ** 2

        trackio.log(
            {
                "x": x,
                "loss_squared": loss,
            }
        )

        return loss

    study = optuna.create_study(direction="minimize")
    study.optimize(
        objective,
        n_trials=5,
        callbacks=[callback],
        n_jobs=1,
    )

    print("Done multi-run test.")


if __name__ == "__main__":
    main()

If the results are not synced, you can do so with the following command:

trackio sync \
  --project toy-optuna-trackio-multirun \
  --space-id AINovice2005/optuna-dashboard

Could you please review?

cc: @nzw0301

@ParagEkbote ParagEkbote marked this pull request as ready for review December 19, 2025 11:11
@not522 not522 assigned not522 and c-bata and unassigned not522 Dec 24, 2025
@c-bata
Copy link
Copy Markdown
Member

c-bata commented Dec 24, 2025

@ParagEkbote Thank you for your pull request. Could you fix the CI error? I think you can skip Python 3.9 test by specifying python_matrix like below:

python_matrix: "['3.9', '3.10', '3.11', '3.12', '3.13']"

@c-bata c-bata added the feature Change that does not break compatibility, but affects the public interfaces. label Dec 24, 2025
Copy link
Copy Markdown
Member

@c-bata c-bata left a comment

Choose a reason for hiding this comment

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

Thank you the updates! I left an early feedback comment.

Due to the year-end and New Year holidays, my review may take a bit longer than usual. I’ll get back to you once I’m able to resume the review.

@ParagEkbote ParagEkbote requested a review from c-bata December 26, 2025 14:17
@github-actions
Copy link
Copy Markdown

github-actions bot commented Jan 4, 2026

This pull request has not seen any recent activity.

@github-actions github-actions bot added the stale Exempt from stale bot labeling. label Jan 4, 2026
@c-bata c-bata removed the stale Exempt from stale bot labeling. label Jan 5, 2026
@ParagEkbote
Copy link
Copy Markdown
Contributor Author

Could you please review the changes?

cc: @c-bata

Copy link
Copy Markdown
Member

@c-bata c-bata left a comment

Choose a reason for hiding this comment

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

I left two early feedback comments 🙏

@@ -0,0 +1,203 @@
from __future__ import annotations
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

My first impression is that most of these test scenarios rely heavily on unittest.mock, which makes it difficult to see the long-term value of maintaining them.

For example, if TrackioCallback were to break due to future changes in trackio, these tests would not detect that issue. Given this, I wonder if it might make sense to remove these tests. What do you think?

Copy link
Copy Markdown
Contributor Author

@ParagEkbote ParagEkbote Jan 9, 2026

Choose a reason for hiding this comment

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

I have modeled them similarly to the WeightsAndBiasesCallback tests, since the public api of trackio is modeled based on wandb. What type of alternative testing strategy do you think would work?

cc: @c-bata

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

One option might be to remove these tests altogether. Since they rely heavily on mocks, I’m not sure they provide much value in catching real regressions in trackio itself.

The only alternative I can think of would be integration tests against the actual trackio behavior, but those tend to be fragile and hard to maintain. From a maintainability perspective, I would personally prefer to avoid such tests and instead address issues as they are reported.

Copy link
Copy Markdown
Contributor Author

@ParagEkbote ParagEkbote Jan 13, 2026

Choose a reason for hiding this comment

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

I have removed the tests and can also remove the gh-action additions if required . Could you please review?

ParagEkbote and others added 2 commits January 9, 2026 19:21
Co-authored-by: c-bata <contact@c-bata.link>
@ParagEkbote ParagEkbote requested a review from c-bata January 13, 2026 18:18
Copy link
Copy Markdown
Member

@c-bata c-bata left a comment

Choose a reason for hiding this comment

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

Thank you for the update. Changes itself look good to me. I will merge this PR after following CI issue will be resolved:
https://github.com/optuna/optuna-integration/actions/runs/20967917853/job/60551934863?pr=259

@c-bata
Copy link
Copy Markdown
Member

c-bata commented Jan 16, 2026

@ParagEkbote Thank you for your investigation. It seems that the cause of the problem is not related to your changes. I’m now investigating the root cause. 🙏

@c-bata
Copy link
Copy Markdown
Member

c-bata commented Jan 16, 2026

@ParagEkbote I fixed the CI issue at #264. Could you merge the latest main branch? 🙏

@ParagEkbote ParagEkbote requested a review from c-bata January 16, 2026 07:29
Copy link
Copy Markdown
Member

@c-bata c-bata left a comment

Choose a reason for hiding this comment

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

Thank you for the update.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature Change that does not break compatibility, but affects the public interfaces.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add trackio integration

3 participants