lightray 0.2.3__tar.gz → 0.2.5__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,26 +1,20 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.4
2
2
  Name: lightray
3
- Version: 0.2.3
3
+ Version: 0.2.5
4
4
  Summary: Distribute a LightningCLI hyperparameter search with Ray Tune
5
- License: MIT
6
- Author: Ethan Jacob Marx
7
- Author-email: ethan.marx@ligo.org
8
- Requires-Python: >=3.9,<4.0
9
- Classifier: License :: OSI Approved :: MIT License
10
- Classifier: Programming Language :: Python :: 3
11
- Classifier: Programming Language :: Python :: 3.9
12
- Classifier: Programming Language :: Python :: 3.10
13
- Classifier: Programming Language :: Python :: 3.11
14
- Classifier: Programming Language :: Python :: 3.12
15
- Classifier: Programming Language :: Python :: 3.13
16
- Requires-Dist: jsonargparse[signatures] (>=4.33.2,<5.0.0)
17
- Requires-Dist: lightning (<=2.4.0)
18
- Requires-Dist: omegaconf (>=2.3.0,<3.0.0)
19
- Requires-Dist: pyarrow (>=17.0.0,<18.0.0)
20
- Requires-Dist: ray[default,tune] (>=2.8.0,<3.0.0)
21
- Requires-Dist: s3fs (>=2024.9.0,<2025.0.0)
22
- Requires-Dist: wandb (>=0.18.5,<0.19.0)
5
+ Author-email: Ethan Jacob Marx <ethan.marx@ligo.org>
6
+ Maintainer-email: Will Benoit <william.benoit@ligo.org>
7
+ License-Expression: MIT
8
+ Project-URL: Repository, https://github.com/ML4GW/lightray
9
+ Requires-Python: <3.15,>=3.11
23
10
  Description-Content-Type: text/markdown
11
+ Requires-Dist: ray[default,tune]<3,>=2.41
12
+ Requires-Dist: lightning>=2.4.0
13
+ Requires-Dist: s3fs>=2024.9.0
14
+ Requires-Dist: pyarrow>=17
15
+ Requires-Dist: jsonargparse[signatures]<5,>=4.50
16
+ Requires-Dist: omegaconf<3,>=2.3.0
17
+ Requires-Dist: botocore
24
18
 
25
19
  # lightray
26
20
  A CLI for easily integrating `LightningCLI` with `RayTune` hyperparameter optimization
@@ -76,23 +70,21 @@ tune_config:
76
70
  num_samples: 1
77
71
  reuse_actors: true
78
72
 
79
- # ray.train.RunConfig
73
+ # ray.tune.RunConfig
80
74
  run_config:
81
75
  name: "my-first-run"
82
76
  storage_path: s3://aframe-test/new-tune/
77
+ # ray.tune.FailureConfig
83
78
  failure_config:
84
- class_path: ray.train.FailureConfig
85
- init_args:
86
- max_failures: 1
79
+ max_failures: 1
80
+ # ray.tune.CheckpointConfig
87
81
  checkpoint_config:
88
- class_path: ray.train.CheckpointConfig
89
- init_args:
90
- num_to_keep: 5
91
- checkpoint_score_attribute: "val_loss"
92
- checkpoint_score_order: "min"
82
+ num_to_keep: 5
83
+ checkpoint_score_attribute: "val_loss"
84
+ checkpoint_score_order: "min"
93
85
  verbose: null
94
86
 
95
- # ray.train.SyncConfig
87
+ # ray.tune.SyncConfig
96
88
  sync_config:
97
89
  sync_period: 1000
98
90
 
@@ -146,4 +138,3 @@ To connect to a remote ray cluster, pass the ip address (using port `10001`) to
146
138
  ```console
147
139
  lightray --config tune.yaml --ray_init.address ray://{ip}:10001 -- --config cli.yaml
148
140
  ```
149
-
@@ -52,23 +52,21 @@ tune_config:
52
52
  num_samples: 1
53
53
  reuse_actors: true
54
54
 
55
- # ray.train.RunConfig
55
+ # ray.tune.RunConfig
56
56
  run_config:
57
57
  name: "my-first-run"
58
58
  storage_path: s3://aframe-test/new-tune/
59
+ # ray.tune.FailureConfig
59
60
  failure_config:
60
- class_path: ray.train.FailureConfig
61
- init_args:
62
- max_failures: 1
61
+ max_failures: 1
62
+ # ray.tune.CheckpointConfig
63
63
  checkpoint_config:
64
- class_path: ray.train.CheckpointConfig
65
- init_args:
66
- num_to_keep: 5
67
- checkpoint_score_attribute: "val_loss"
68
- checkpoint_score_order: "min"
64
+ num_to_keep: 5
65
+ checkpoint_score_attribute: "val_loss"
66
+ checkpoint_score_order: "min"
69
67
  verbose: null
70
68
 
71
- # ray.train.SyncConfig
69
+ # ray.tune.SyncConfig
72
70
  sync_config:
73
71
  sync_period: 1000
74
72
 
@@ -3,7 +3,7 @@ import time
3
3
  from typing import Literal
4
4
 
5
5
  from botocore.exceptions import ClientError, ConnectTimeoutError
6
- from ray import train
6
+ from ray import tune
7
7
  from ray.tune.integration.pytorch_lightning import TuneReportCheckpointCallback
8
8
 
9
9
  BOTO_RETRY_EXCEPTIONS = (ClientError, ConnectTimeoutError)
@@ -11,12 +11,12 @@ BOTO_RETRY_EXCEPTIONS = (ClientError, ConnectTimeoutError)
11
11
 
12
12
  def report_with_retries(metrics, checkpoint=None, retries: int = 10):
13
13
  """
14
- Call `train.report`, which will persist checkpoints to s3,
14
+ Call `tune.report`, which will persist checkpoints to s3,
15
15
  retrying after any possible errors
16
16
  """
17
17
  for _ in range(retries):
18
18
  try:
19
- train.report(metrics=metrics, checkpoint=checkpoint)
19
+ tune.report(metrics=metrics, checkpoint=checkpoint)
20
20
  break
21
21
  except BOTO_RETRY_EXCEPTIONS:
22
22
  time.sleep(5)
@@ -26,7 +26,7 @@ def report_with_retries(metrics, checkpoint=None, retries: int = 10):
26
26
  class LightRayReportCheckpointCallback(TuneReportCheckpointCallback):
27
27
  """
28
28
  Subclass of Rays TuneReportCheckpointCallback
29
- with addition of a retry mechanism to the `train.report`
29
+ with addition of a retry mechanism to the `tune.report`
30
30
  call to handle transient s3 errors.
31
31
 
32
32
  Adds a `checkpoint_every` parameter to the constructor
@@ -88,6 +88,6 @@ class LightRayReportCheckpointCallback(TuneReportCheckpointCallback):
88
88
  logging.debug(f"Reporting checkpoint on epoch {self.step}")
89
89
  report_with_retries(report_dict, checkpoint=checkpoint)
90
90
  else:
91
- train.report(metrics=report_dict)
91
+ tune.report(metrics=report_dict)
92
92
 
93
93
  self.step += 1
@@ -16,7 +16,7 @@ from jsonargparse import (
16
16
  capture_parser,
17
17
  )
18
18
  from lightning.pytorch.cli import LightningCLI
19
- from ray import train, tune
19
+ from ray import tune
20
20
  from ray.tune.integration.pytorch_lightning import TuneCallback
21
21
 
22
22
  from lightray import fs, utils
@@ -28,11 +28,11 @@ def cli(args=None):
28
28
  parser.add_subclass_arguments(TuneCallback, "tune_callback")
29
29
  parser.add_class_arguments(tune.TuneConfig, "tune_config")
30
30
  parser.add_class_arguments(
31
- train.RunConfig, "run_config", skip="storage_filesystem"
31
+ tune.RunConfig, "run_config", skip="storage_filesystem"
32
32
  )
33
33
  # TODO: use add class arguments from tune.Tuner directly
34
34
  # see https://github.com/omni-us/jsonargparse/issues/609
35
- parser.add_class_arguments(train.SyncConfig, "sync_config")
35
+ parser.add_class_arguments(tune.SyncConfig, "sync_config")
36
36
  parser.add_function_arguments(ray.init, "ray_init")
37
37
  parser.add_argument(
38
38
  "--lightning_cli_cls",
@@ -49,12 +49,12 @@ def cli(args=None):
49
49
  parser.add_argument("--cpus_per_trial", type=int, default=1)
50
50
 
51
51
  parser.link_arguments(
52
- "run_config.checkpoint_config.checkpoint_score_attribute",
52
+ "run_config.checkpoint_config.init_args.checkpoint_score_attribute",
53
53
  "tune_callback.init_args.metric",
54
54
  apply_on="parse",
55
55
  )
56
56
  parser.link_arguments(
57
- "run_config.checkpoint_config.checkpoint_score_order",
57
+ "run_config.checkpoint_config.init_args.checkpoint_score_order",
58
58
  "tune_callback.init_args.mode",
59
59
  apply_on="parse",
60
60
  )
@@ -97,7 +97,7 @@ def cli(args=None):
97
97
 
98
98
  # instantiate tune related classes from config
99
99
  # and parse the parameter space
100
- cfg_init = parser.instantiate_classes(cfg)
100
+ cfg_init = parser.instantiate(cfg)
101
101
  cfg_init.run_config.sync_config = cfg_init.sync_config
102
102
  utils.eval_tune_run_config(cfg_init.param_space)
103
103
 
@@ -5,7 +5,7 @@ from typing import Type
5
5
  from unittest.mock import patch
6
6
 
7
7
  from lightning.pytorch.cli import LightningCLI
8
- from ray import train, tune
8
+ from ray import tune
9
9
 
10
10
  re_tune_func = re.compile(r"^tune.(\w+)\((.+)\)$")
11
11
 
@@ -40,7 +40,7 @@ def get_trainable(
40
40
  args.append(f"--{key}={val}")
41
41
 
42
42
  # setup lightning logger path to point to ray trial dir
43
- log_dir = train.get_context().get_trial_dir()
43
+ log_dir = tune.get_context().get_trial_dir()
44
44
  args.append(f"--trainer.logger.save_dir={log_dir}")
45
45
 
46
46
  # get ckpt prefix based on fs
@@ -50,7 +50,7 @@ def get_trainable(
50
50
  ckpt_prefix = "s3://"
51
51
 
52
52
  # restore from checkpoint if available
53
- checkpoint = train.get_checkpoint()
53
+ checkpoint = tune.get_checkpoint()
54
54
  ckpt_path = None
55
55
  if checkpoint:
56
56
  ckpt_path = os.path.join(
@@ -0,0 +1,140 @@
1
+ Metadata-Version: 2.4
2
+ Name: lightray
3
+ Version: 0.2.5
4
+ Summary: Distribute a LightningCLI hyperparameter search with Ray Tune
5
+ Author-email: Ethan Jacob Marx <ethan.marx@ligo.org>
6
+ Maintainer-email: Will Benoit <william.benoit@ligo.org>
7
+ License-Expression: MIT
8
+ Project-URL: Repository, https://github.com/ML4GW/lightray
9
+ Requires-Python: <3.15,>=3.11
10
+ Description-Content-Type: text/markdown
11
+ Requires-Dist: ray[default,tune]<3,>=2.41
12
+ Requires-Dist: lightning>=2.4.0
13
+ Requires-Dist: s3fs>=2024.9.0
14
+ Requires-Dist: pyarrow>=17
15
+ Requires-Dist: jsonargparse[signatures]<5,>=4.50
16
+ Requires-Dist: omegaconf<3,>=2.3.0
17
+ Requires-Dist: botocore
18
+
19
+ # lightray
20
+ A CLI for easily integrating `LightningCLI` with `RayTune` hyperparameter optimization
21
+
22
+ ## Getting Started
23
+ Imagine you have the following lightning `DataModule`, `LightningModule` and `LightningCLI`
24
+
25
+ ```python
26
+ from lightning.pytorch as pl
27
+
28
+ class DataModule(pl.LightningDataModule):
29
+ def __init__(self, hidden_dim: int, learning_rate: float, parameter: int):
30
+ self.parameter = parameter
31
+ self.hidden_dim = hidden_dim
32
+ self.learning_rate = learning_rate
33
+
34
+ def train_dataloader(self):
35
+ ...
36
+
37
+ class LightningModule(pl.LightningModule):
38
+ def __init__(self, parameter: int):
39
+ self.parameter = parameter
40
+
41
+ def training_step(self):
42
+ ...
43
+
44
+ class CustomCLI(pl.cli.LightningCLI):
45
+ def add_arguments_to_parser(self, parser):
46
+ parser.link_arguments(
47
+ "data.init_args.parameter",
48
+ "model.init_args.parameter",
49
+ apply_on="parse"
50
+ )
51
+
52
+ ```
53
+
54
+ To launching a hyperparameter tuning job with `RayTune` using this `LightningCLI` can be done by configuring
55
+ a `yaml` that looks like the following
56
+
57
+ ```yaml
58
+ # tune.yaml
59
+
60
+ # ray.tune.TuneConfig
61
+ tune_config:
62
+ mode: "min"
63
+ metric: "val_loss"
64
+ scheduler:
65
+ class_path: ray.tune.schedulers.ASHAScheduler
66
+ init_args:
67
+ max_t: 200
68
+ grace_period: 21
69
+ reduction_factor: 2
70
+ num_samples: 1
71
+ reuse_actors: true
72
+
73
+ # ray.tune.RunConfig
74
+ run_config:
75
+ name: "my-first-run"
76
+ storage_path: s3://aframe-test/new-tune/
77
+ # ray.tune.FailureConfig
78
+ failure_config:
79
+ max_failures: 1
80
+ # ray.tune.CheckpointConfig
81
+ checkpoint_config:
82
+ num_to_keep: 5
83
+ checkpoint_score_attribute: "val_loss"
84
+ checkpoint_score_order: "min"
85
+ verbose: null
86
+
87
+ # ray.tune.SyncConfig
88
+ sync_config:
89
+ sync_period: 1000
90
+
91
+ # ray.init
92
+ ray_init:
93
+ address: null
94
+
95
+ # tune.Tune.param_space
96
+ param_space:
97
+ model.learning_rate: tune.loguniform(1e-3, 4)
98
+
99
+ # ray.tune.TuneCallback
100
+ tune_callback:
101
+ class_path: lightray.callbacks.LightRayReportCheckpointCallback
102
+ init_args:
103
+ 'on': "validation_end"
104
+ checkpoint_every: 10
105
+
106
+ # resources per trial
107
+ cpus_per_trial: 2
108
+ gpus_per_trial: 1
109
+
110
+ # lightning cli class to tune
111
+ lightning_cli_cls: example.lightning.Cli
112
+ ```
113
+
114
+ Then, launch the tuning job.
115
+
116
+ ```console
117
+ lightray --config tune.yaml -- --config cli.yaml
118
+ ```
119
+
120
+ Any arguments passed after "--" will automatically be forwarded to the specified `LightningCLI` class as if it were being run from the command line. This way, tuning configuration and training configuration can be kept separate. Also, you can easily utilize existing configuration files compatible with your `LightningCLI`.
121
+
122
+
123
+ ## S3 Support
124
+ In addition, there is automatic support for `s3` storage. Make sure you have set the `AWS_ENDPOINT_URL`, `AWS_ACCESS_KEY_ID`, and `AWS_SECRET_ACCESS_KEY` environment variables.
125
+ Then, simply pass the path to your bucket with the `s3` prefix (e.g. `s3://{bucket}/{folder}`) to the `run_config.storage_path` argument.
126
+
127
+ ```console
128
+ lightray --config tune.yaml --run_config.storage_path s3://{bucket}/{folder}
129
+ ```
130
+
131
+ There is also a wrapper around the `ray.tune.integration.pytorch_lightning.TuneReportCheckpointCallback` that will do checkpoint reporting with retries to handle transient s3 errors.
132
+ This is provided at `lightray.callbacks.LightRayReportCheckpointCallback`
133
+
134
+
135
+ ## Remote cluster
136
+ To connect to a remote ray cluster, pass the ip address (using port `10001`) to `ray_init.address`:
137
+
138
+ ```console
139
+ lightray --config tune.yaml --ray_init.address ray://{ip}:10001 -- --config cli.yaml
140
+ ```
@@ -0,0 +1,14 @@
1
+ README.md
2
+ pyproject.toml
3
+ lightray/__init__.py
4
+ lightray/callbacks.py
5
+ lightray/cli.py
6
+ lightray/fs.py
7
+ lightray/utils.py
8
+ lightray.egg-info/PKG-INFO
9
+ lightray.egg-info/SOURCES.txt
10
+ lightray.egg-info/dependency_links.txt
11
+ lightray.egg-info/entry_points.txt
12
+ lightray.egg-info/requires.txt
13
+ lightray.egg-info/top_level.txt
14
+ tests/test_cli.py
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ lightray = lightray.cli:cli
@@ -0,0 +1,7 @@
1
+ ray[default,tune]<3,>=2.41
2
+ lightning>=2.4.0
3
+ s3fs>=2024.9.0
4
+ pyarrow>=17
5
+ jsonargparse[signatures]<5,>=4.50
6
+ omegaconf<3,>=2.3.0
7
+ botocore
@@ -0,0 +1 @@
1
+ lightray
@@ -0,0 +1,57 @@
1
+ [project]
2
+ name = "lightray"
3
+ dynamic = ["version"]
4
+ description = "Distribute a LightningCLI hyperparameter search with Ray Tune"
5
+ authors = [{ name = "Ethan Jacob Marx", email = "ethan.marx@ligo.org" }]
6
+ maintainers = [{ name = "Will Benoit", email = "william.benoit@ligo.org" }]
7
+ requires-python = ">=3.11,<3.15"
8
+ readme = "README.md"
9
+ license = "MIT"
10
+ dependencies = [
11
+ "ray[default, tune]>=2.41,<3",
12
+ "lightning>=2.4.0",
13
+ "s3fs>=2024.9.0",
14
+ "pyarrow>=17",
15
+ "jsonargparse[signatures]>=4.50,<5",
16
+ "omegaconf>=2.3.0,<3",
17
+ "botocore",
18
+ ]
19
+
20
+ [project.urls]
21
+ Repository = "https://github.com/ML4GW/lightray"
22
+
23
+ [project.scripts]
24
+ lightray = "lightray.cli:cli"
25
+
26
+ [dependency-groups]
27
+ dev = [
28
+ "pre-commit>=3.8.0,<4",
29
+ "pytest>=8.3.2,<9",
30
+ ]
31
+
32
+ [tool.setuptools.packages.find]
33
+ include = ["lightray*"]
34
+
35
+ [tool.setuptools-git-versioning]
36
+ enabled = true
37
+ # skip the helm chart release tags (ray-cluster-*)
38
+ tag_filter = "v.*"
39
+ dev_template = "{tag}.post{ccount}+git.{sha}"
40
+
41
+ [build-system]
42
+ requires = [ "setuptools>=77.0.3", "wheel", "setuptools-git-versioning>=2.0,<4",]
43
+ build-backend = "setuptools.build_meta"
44
+
45
+ [tool.ruff]
46
+ line-length = 79
47
+ extend-exclude = ["docs"]
48
+
49
+
50
+ [tool.ruff.lint]
51
+ mccabe = {"max-complexity" = 18}
52
+ select = ["B", "C", "E", "F", "W", "B9", "T201"]
53
+ ignore = ["W605", "E203"] # ignore for consistency with black
54
+
55
+ # ignore asterisk imports and unused
56
+ # import errors in __init__ files
57
+ per-file-ignores = {"**/__init__.py" = ["F401", "F403"]}
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,2 @@
1
+ def test():
2
+ assert True
@@ -1,47 +0,0 @@
1
- [tool.poetry]
2
- name = "lightray"
3
- version = "0.2.3"
4
- description = "Distribute a LightningCLI hyperparameter search with Ray Tune"
5
- authors = ["Ethan Jacob Marx <ethan.marx@ligo.org>"]
6
- license = "MIT"
7
- readme = "README.md"
8
-
9
- [tool.poetry.dependencies]
10
- python = "^3.9"
11
- ray = {version = "^2.8.0", extras = ["default", "tune"]}
12
- lightning = "<=2.4.0"
13
- s3fs = {version = "^2024.9.0"}
14
- pyarrow = {version = "^17.0.0"}
15
- jsonargparse = {version = "^4.33.2", extras = ["signatures"]}
16
- wandb = "^0.18.5"
17
- omegaconf = "^2.3.0"
18
-
19
-
20
- [tool.poetry.scripts]
21
- lightray = "lightray.cli:cli"
22
-
23
- [tool.poetry.group.dev.dependencies]
24
- pre-commit = "^3.8.0"
25
- pytest = "^8.3.2"
26
-
27
- [build-system]
28
- requires = ["poetry-core"]
29
- build-backend = "poetry.core.masonry.api"
30
-
31
- [tool.black]
32
- line-length = 79
33
- include = '\.pyi?$'
34
- exclude = '''
35
- /(
36
- \.git
37
- | \.tox
38
- | _build
39
- | dist
40
- | docs
41
- )/
42
- '''
43
-
44
-
45
- [tool.isort]
46
- multi_line_output = 3
47
- include_trailing_comma = true
File without changes
File without changes