Skip to content

Commit

Permalink
✨ feat: add support for generate-commands
Browse files Browse the repository at this point in the history
  • Loading branch information
zrr1999 committed Oct 22, 2024
1 parent 75e1044 commit 83de3ed
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 5 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,6 @@ if __name__ == "__main__":
To use Nanoflow as a cli or tui, you can use the following command:

```shell
nanoflow examples/simple.toml
nanoflow examples/simple.toml --use-tui
nanoflow run examples/simple.toml
nanoflow run examples/simple.toml --use-tui
```
13 changes: 13 additions & 0 deletions nanoflow/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

from nanoflow import WorkflowConfig
from nanoflow.executor import Executor
from nanoflow.utils import layer_nodes

app = typer.Typer()

Expand Down Expand Up @@ -40,3 +41,15 @@ async def start():
else:
executor = Executor.from_configs(workflow_config)
executor.run()


@app.command()
def generate_commands(config_path: Path):
handler = RichHandler(highlighter=NullHighlighter(), markup=True)
init_logger("DEBUG", handler)
workflow_config = WorkflowConfig.model_validate(toml.load(config_path))
layered_nodes = layer_nodes(workflow_config.to_nodes())
for i, layer in enumerate(layered_nodes):
logger.info(f"Layer {i}")
for node in layer:
print(workflow_config.tasks[node].get_command())
4 changes: 3 additions & 1 deletion nanoflow/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ def from_configs(
layered_nodes = layer_nodes(config.to_nodes())
resources = config.resources
if resources == "gpus":
resource_pool = ResourcePool(get_available_gpus())
gpus = get_available_gpus()
logger.info(f"Found {len(gpus)} GPUs")
resource_pool = ResourcePool(gpus)
layered_tasks = [
[
create_gpu_task(node, config.tasks[node].get_command(), pool=resource_pool, update_hook=update_hook)
Expand Down
4 changes: 2 additions & 2 deletions tests/test_e2e.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def test_cli(config_path: str):
from nanoflow.__main__ import app

runner = CliRunner()
result = runner.invoke(app, [config_path])
result = runner.invoke(app, ["run", config_path])
assert result.exit_code == 0, f"Exit code was {result.exit_code}, expected 0. Error: {result.exc_info}"


Expand All @@ -24,7 +24,7 @@ def test_cli_error():
from nanoflow.__main__ import app

runner = CliRunner()
result = runner.invoke(app, ["./examples/error.toml"])
result = runner.invoke(app, ["run", "./examples/error.toml"])
assert result.exit_code != 0


Expand Down

0 comments on commit 83de3ed

Please sign in to comment.