1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
- import os
- import time
- from git import Repo, GitCommandError
- import mlflow
- import dagshub
- from ray import air, tune
- from ray.air import session
- from ray.air.integrations.dagshub import setup_dagshub, upload_artifacts
- def evaluation_fn(step, width, height):
- return (0.1 + width * step / 100) ** (-1) + height * 0.1
- def train_function_dagshub(config):
- # Hyperparameters
- width, height = config["width"], config["height"]
- setup_dagshub(config=config)
-
- for step in range(config.get("steps", 100)):
- # Iterative training function - can be any arbitrary training procedure
- intermediate_score = evaluation_fn(step, width, height)
- # Log the metrics to mlflow
- mlflow.log_metrics(dict(mean_loss=intermediate_score), step=step)
- # Feed the score back to Tune.
- session.report({"iterations": step, "mean_loss": intermediate_score})
- time.sleep(0.1)
- def tune_with_setup(save_artifact=False):
- DAGSHUB_REPO = "timho102003/raytest_0607_v12"
- dagshub.init(repo_name=DAGSHUB_REPO.split(os.sep)[1], repo_owner=DAGSHUB_REPO.split(os.sep)[0])
- # Set the experiment, or create a new one if does not exist yet.
- mlflow.set_tracking_uri(os.getenv("MLFLOW_TRACKING_URI", None))
- mlflow.set_experiment(experiment_name="mixin_example")
- tuner = tune.Tuner(
- train_function_dagshub,
- tune_config=tune.TuneConfig(
- num_samples=5
- ),
- run_config=air.RunConfig(
- name="dagshub",
- ),
- param_space={
- "width": tune.randint(10, 100),
- "height": tune.randint(0, 100),
- "steps": 5,
- "dagshub": {
- "experiment_name": "mixin_example",
- "dagshub_repository": DAGSHUB_REPO,
- "log_mlflow_only": False,
- },
- },
- )
- results = tuner.fit()
- if save_artifact:
- print("Save Artifact!")
- upload_artifacts(results=results, repo_name=DAGSHUB_REPO.split(os.sep)[1], repo_owner=DAGSHUB_REPO.split(os.sep)[0])
- tune_with_setup(save_artifact=True)
|