Skip to content

Commit 2ed7282

Browse files
justusschockpre-commit-ci[bot]Borda
authored
Rename Lightning Fabric CLI (#19442)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Jirka Borovec <6035284+Borda@users.noreply.github.com>
1 parent 47c8f4c commit 2ed7282

File tree

6 files changed

+57
-16
lines changed

6 files changed

+57
-16
lines changed

docs/source-fabric/fundamentals/launch.rst

+6-6
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ An alternative way to launch your Python script in multiple processes is to use
6767

6868
.. code-block:: bash
6969
70-
lightning run model path/to/your/script.py
70+
fabric run model path/to/your/script.py
7171
7272
This is essentially the same as running ``python path/to/your/script.py``, but it also lets you configure the following settings externally without changing your code:
7373

@@ -80,9 +80,9 @@ This is essentially the same as running ``python path/to/your/script.py``, but i
8080

8181
.. code-block:: bash
8282
83-
lightning run model --help
83+
fabric run model --help
8484
85-
Usage: lightning run model [OPTIONS] SCRIPT [SCRIPT_ARGS]...
85+
Usage: fabric run model [OPTIONS] SCRIPT [SCRIPT_ARGS]...
8686
8787
Run a Lightning Fabric script.
8888
@@ -128,7 +128,7 @@ Here is how you run DDP with 8 GPUs and `torch.bfloat16 <https://pytorch.org/doc
128128

129129
.. code-block:: bash
130130
131-
lightning run model ./path/to/train.py \
131+
fabric run model ./path/to/train.py \
132132
--strategy=ddp \
133133
--devices=8 \
134134
--accelerator=cuda \
@@ -138,7 +138,7 @@ Or `DeepSpeed Zero3 <https://www.deepspeed.ai/2021/03/07/zero3-offload.html>`_ w
138138

139139
.. code-block:: bash
140140
141-
lightning run model ./path/to/train.py \
141+
fabric run model ./path/to/train.py \
142142
--strategy=deepspeed_stage_3 \
143143
--devices=8 \
144144
--accelerator=cuda \
@@ -148,7 +148,7 @@ Or `DeepSpeed Zero3 <https://www.deepspeed.ai/2021/03/07/zero3-offload.html>`_ w
148148

149149
.. code-block:: bash
150150
151-
lightning run model ./path/to/train.py \
151+
fabric run model ./path/to/train.py \
152152
--devices=auto \
153153
--accelerator=auto \
154154
--precision=16

src/lightning/__setup__.py

+2
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,8 @@ def _setup_args() -> Dict[str, Any]:
114114
"python_requires": ">=3.8", # todo: take the lowes based on all packages
115115
"entry_points": {
116116
"console_scripts": [
117+
"fabric = lightning.fabric.cli:_main",
118+
"lightning = lightning.fabric.cli:_legacy_main",
117119
"lightning_app = lightning:_cli_entry_point",
118120
],
119121
},

src/lightning/fabric/CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
1717

1818
### Changed
1919

20-
-
20+
- Rename `lightning run model` to `fabric run model` ([#19442](https://github.com/Lightning-AI/pytorch-lightning/pull/19442))
2121

2222
-
2323

src/lightning/fabric/cli.py

+29-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
import logging
1515
import os
1616
import re
17+
import subprocess
18+
import sys
1719
from argparse import Namespace
1820
from typing import Any, List, Optional
1921

@@ -29,6 +31,7 @@
2931
_log = logging.getLogger(__name__)
3032

3133
_CLICK_AVAILABLE = RequirementCache("click")
34+
_LIGHTNING_SDK_AVAILABLE = RequirementCache("lightning_sdk")
3235

3336
_SUPPORTED_ACCELERATORS = ("cpu", "gpu", "cuda", "mps", "tpu")
3437

@@ -44,7 +47,32 @@ def _get_supported_strategies() -> List[str]:
4447
if _CLICK_AVAILABLE:
4548
import click
4649

47-
@click.command(
50+
def _legacy_main() -> None:
51+
"""Legacy CLI handler for fabric.
52+
53+
Raises deprecation warning and runs through fabric cli if necessary, else runs the entrypoint directly
54+
55+
"""
56+
print("`lightning run model` is deprecated and will be removed in future versions."
57+
" Please call `fabric run model` instead.")
58+
args = sys.argv[1:]
59+
if args and args[0] == "run" and args[1] == "model":
60+
_main()
61+
return
62+
63+
if _LIGHTNING_SDK_AVAILABLE:
64+
subprocess.run([sys.executable, "-m", "lightning_sdk.cli.entrypoint"] + args)
65+
return
66+
67+
@click.group()
68+
def _main() -> None:
69+
pass
70+
71+
@_main.group()
72+
def run() -> None:
73+
pass
74+
75+
@run.command(
4876
"model",
4977
context_settings={
5078
"ignore_unknown_options": True,

src/lightning_fabric/__setup__.py

+5
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,11 @@ def _setup_args() -> Dict[str, Any]:
7878
"install_requires": assistant.load_requirements(
7979
_PATH_REQUIREMENTS, unfreeze="none" if _FREEZE_REQUIREMENTS else "all"
8080
),
81+
"entry_points": {
82+
"console_scripts": [
83+
"fabric = lightning_fabric.cli:_main",
84+
],
85+
},
8186
"extras_require": _prepare_extras(),
8287
"project_urls": {
8388
"Bug Tracker": "https://github.com/Lightning-AI/lightning/issues",

tests/tests_fabric/test_cli.py

+14-8
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121

2222
import pytest
2323
from lightning.fabric.cli import _get_supported_strategies, _run_model
24-
from lightning_utilities.core.imports import ModuleAvailableCache
2524

2625
from tests_fabric.helpers.runif import RunIf
2726

@@ -176,13 +175,20 @@ def test_cli_torchrun_num_processes_launched(_, devices, expected, monkeypatch,
176175
)
177176

178177

178+
def test_cli_through_fabric_entry_point():
179+
result = subprocess.run("fabric run model --help", capture_output=True, text=True, shell=True)
180+
181+
message = "Usage: fabric run model [OPTIONS] SCRIPT [SCRIPT_ARGS]"
182+
assert message in result.stdout or message in result.stderr
183+
179184
@pytest.mark.skipif("lightning.fabric" == "lightning_fabric", reason="standalone package")
180185
def test_cli_through_lightning_entry_point():
181186
result = subprocess.run("lightning run model --help", capture_output=True, text=True, shell=True)
182-
if not ModuleAvailableCache("lightning.app"):
183-
message = "The `lightning` command requires additional dependencies"
184-
assert message in result.stdout or message in result.stderr
185-
assert result.returncode != 0
186-
else:
187-
message = "Usage: lightning run model [OPTIONS] SCRIPT [SCRIPT_ARGS]"
188-
assert message in result.stdout or message in result.stderr
187+
188+
deprecation_message = (
189+
"`lightning run model` is deprecated and will be removed in future versions. "
190+
"Please call `fabric run model` instead"
191+
)
192+
message = "Usage: lightning run model [OPTIONS] SCRIPT [SCRIPT_ARGS]"
193+
assert deprecation_message in result.stdout
194+
assert message in result.stdout or message in result.stderr

0 commit comments

Comments
 (0)