Skip to content

Commit af6fb10

Browse files
authored
Merge branch 'main' into fix/new-playwright
2 parents e71fc9e + f4ddaaa commit af6fb10

4 files changed

Lines changed: 76 additions & 3 deletions

File tree

cli/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "transformerlab-cli"
7-
version = "0.0.47"
7+
version = "0.0.48"
88
description = "Transformer Lab CLI"
99
requires-python = ">=3.10"
1010
authors = [{ name = "Transformer Lab", email = "hello@transformerlab.ai" }]

cli/src/transformerlab_cli/commands/task.py

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -825,6 +825,8 @@ def build_launch_payload(
825825
param_values: dict | None = None,
826826
resource_overrides: dict | None = None,
827827
description: str | None = None,
828+
enable_profiling: bool = False,
829+
enable_profiling_torch: bool = False,
828830
) -> dict:
829831
"""Build the payload for launching a task on a provider."""
830832
cfg = task.get("config") or {}
@@ -852,6 +854,8 @@ def pick(field: str):
852854
"accelerators": pick("accelerators"),
853855
"num_nodes": pick("num_nodes"),
854856
"minutes_requested": pick("minutes_requested"),
857+
"enable_profiling": enable_profiling,
858+
"enable_profiling_torch": enable_profiling_torch,
855859
"env_vars": task.get("env_vars", {}),
856860
"parameters": task.get("parameters", {}),
857861
"config": param_values if param_values else None,
@@ -1016,6 +1020,8 @@ def queue_task(
10161020
interactive: bool = True,
10171021
description: str | None = None,
10181022
param_overrides: dict | None = None,
1023+
enable_profiling: bool = False,
1024+
enable_profiling_torch: bool = False,
10191025
) -> None:
10201026
"""Queue a task on a compute provider."""
10211027
with console.status("[bold success]Fetching task...[/bold success]", spinner="dots"):
@@ -1067,8 +1073,17 @@ def queue_task(
10671073
param_values = {k: (v.get("default", "") if isinstance(v, dict) else v) for k, v in parameters.items()}
10681074
param_values.update(overrides)
10691075

1076+
if enable_profiling_torch and not enable_profiling:
1077+
raise typer.BadParameter("--enable-profiling-torch requires --enable-profiling.")
1078+
10701079
payload = build_launch_payload(
1071-
task, provider.get("name"), param_values, resource_overrides, description=description
1080+
task,
1081+
provider.get("name"),
1082+
param_values,
1083+
resource_overrides,
1084+
description=description,
1085+
enable_profiling=enable_profiling,
1086+
enable_profiling_torch=enable_profiling_torch,
10721087
)
10731088
provider_id = provider.get("id")
10741089

@@ -1105,6 +1120,16 @@ def command_task_queue(
11051120
"scalar (e.g. score=0.42 -> float, enabled=true -> bool). Unknown keys fail."
11061121
),
11071122
),
1123+
enable_profiling: bool = typer.Option(
1124+
False,
1125+
"--enable-profiling",
1126+
help="Enable system profiling for this run (CPU/GPU/memory sampling).",
1127+
),
1128+
enable_profiling_torch: bool = typer.Option(
1129+
False,
1130+
"--enable-profiling-torch",
1131+
help="Enable torch profiler trace export for this run (requires --enable-profiling).",
1132+
),
11081133
):
11091134
"""Queue a task on a compute provider."""
11101135
current_experiment = require_current_experiment()
@@ -1119,6 +1144,8 @@ def command_task_queue(
11191144
interactive=not no_interactive,
11201145
description=description,
11211146
param_overrides=param_overrides,
1147+
enable_profiling=enable_profiling,
1148+
enable_profiling_torch=enable_profiling_torch,
11221149
)
11231150

11241151

cli/tests/commands/test_task.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,14 @@ def test_build_launch_payload_omits_description_by_default():
9595
assert payload["description"] is None
9696

9797

98+
def test_build_launch_payload_includes_profiling_flags():
99+
"""build_launch_payload forwards profiling flags to the launch API body."""
100+
task = {"id": "t1", "name": "finetune", "experiment_id": "exp1", "run": "python main.py"}
101+
payload = build_launch_payload(task, "Local", enable_profiling=True, enable_profiling_torch=True)
102+
assert payload["enable_profiling"] is True
103+
assert payload["enable_profiling_torch"] is True
104+
105+
98106
SAMPLE_TASK = {
99107
"id": "t1",
100108
"name": "finetune",
@@ -264,6 +272,44 @@ def test_task_queue_param_when_task_has_no_parameters_errors(_mock_exp, _mock_ge
264272
mock_post.assert_not_called()
265273

266274

275+
@patch("transformerlab_cli.commands.task.api.post_json", return_value=_mock_resp({"job_id": "j1"}))
276+
@patch("transformerlab_cli.commands.task.fetch_providers", return_value=SAMPLE_PROVIDERS)
277+
@patch("transformerlab_cli.commands.task.api.get", return_value=_mock_resp(SAMPLE_TASK))
278+
@patch("transformerlab_cli.commands.task.require_current_experiment", return_value="exp1")
279+
def test_task_queue_enable_profiling_flags(_mock_exp, _mock_get, _mock_providers, mock_post):
280+
"""Queue command forwards profiling flags into launch payload."""
281+
result = runner.invoke(
282+
app,
283+
[
284+
"task",
285+
"queue",
286+
"t1",
287+
"--no-interactive",
288+
"--enable-profiling",
289+
"--enable-profiling-torch",
290+
],
291+
)
292+
assert result.exit_code == 0, result.output
293+
_path, body = mock_post.call_args.args
294+
assert body["enable_profiling"] is True
295+
assert body["enable_profiling_torch"] is True
296+
297+
298+
@patch("transformerlab_cli.commands.task.api.post_json", return_value=_mock_resp({"job_id": "j1"}))
299+
@patch("transformerlab_cli.commands.task.fetch_providers", return_value=SAMPLE_PROVIDERS)
300+
@patch("transformerlab_cli.commands.task.api.get", return_value=_mock_resp(SAMPLE_TASK))
301+
@patch("transformerlab_cli.commands.task.require_current_experiment", return_value="exp1")
302+
def test_task_queue_enable_torch_profiling_requires_profiling(_mock_exp, _mock_get, _mock_providers, mock_post):
303+
"""Torch profiling flag without base profiling fails with a clear error."""
304+
result = runner.invoke(
305+
app,
306+
["task", "queue", "t1", "--no-interactive", "--enable-profiling-torch"],
307+
)
308+
assert result.exit_code != 0
309+
assert "requires --enable-profiling" in strip_ansi(result.output).lower()
310+
mock_post.assert_not_called()
311+
312+
267313
@patch(
268314
"transformerlab_cli.commands.task.api.post_json",
269315
side_effect=[

cli/uv.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)