-
Notifications
You must be signed in to change notification settings - Fork 26
feat: add basic observability tracing to dora-smolagents node #55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
DEFAULTE-R
wants to merge
10
commits into
dora-rs:main
Choose a base branch
from
DEFAULTE-R:feat/agent-observability-trace
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
c3ea9bf
feat(node-hub): add dora-tflite edge inference node for constrained d…
DEFAULTE-R 0498a27
feat(node-hub): add tests and fix pyproject.toml for dora-tflite node
DEFAULTE-R 2fd1375
Potential fix for pull request finding
DEFAULTE-R c0f637a
fix(node-hub/dora-tflite): address Copilot review feedback
DEFAULTE-R 4b0d835
feat: add smolagents-based agent node with Ollama support
DEFAULTE-R f0b4309
feat: add observability tracing to dora-smolagents node
DEFAULTE-R 9407217
fix: replace broken smolagents folder with proper submodule
DEFAULTE-R 63f5fd6
chore: update smolagents submodule to latest fixed version
DEFAULTE-R 70b3079
fix: align dora-node-api with message format v0.8
DEFAULTE-R 44c1a20
fix: correct dependencies and narrow test exception handling
DEFAULTE-R File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule dora-smolagents
added at
56e9aa
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| # dora-tflite | ||
|
|
||
| A Dora node for running TensorFlow Lite inference on edge and constrained devices (Raspberry Pi, microcontrollers). | ||
|
|
||
| ## Installation | ||
|
|
||
| ```bash | ||
| pip install dora-tflite | ||
| ``` | ||
|
|
||
| ## Usage | ||
|
|
||
| ```yaml | ||
| nodes: | ||
| - id: tflite-inference | ||
| path: dora-tflite | ||
| inputs: | ||
| tensor: source/tensor | ||
| outputs: | ||
| - inference | ||
| env: | ||
| MODEL: path/to/model.tflite | ||
| ``` | ||
|
|
||
| ## Inputs | ||
|
|
||
| - `tensor`: Input tensor as a flat array (PyArrow) | ||
|
|
||
| ## Outputs | ||
|
|
||
| - `inference`: Output tensor as a flat array (PyArrow) | ||
|
|
||
| ## Environment Variables | ||
|
|
||
| - `MODEL`: Path to the .tflite model file (default: model.tflite) | ||
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| """Dora node for TensorFlow Lite inference on edge/constrained devices.""" | ||
|
|
||
| import argparse | ||
| import os | ||
|
|
||
| import numpy as np | ||
| import pyarrow as pa | ||
| from dora import Node | ||
|
|
||
|
|
||
| def main(): | ||
| """Run the dora-tflite inference node.""" | ||
| parser = argparse.ArgumentParser( | ||
| description="dora-tflite: TensorFlow Lite inference node for edge deployment.", | ||
| ) | ||
| parser.add_argument( | ||
| "--name", | ||
| type=str, | ||
| required=False, | ||
| help="The name of the node in the dataflow.", | ||
| default="dora-tflite", | ||
| ) | ||
| parser.add_argument( | ||
| "--model", | ||
| type=str, | ||
| required=False, | ||
| help="Path to the .tflite model file.", | ||
| default="model.tflite", | ||
| ) | ||
| args = parser.parse_args() | ||
|
|
||
| model_path = os.getenv("MODEL", args.model) | ||
|
|
||
| try: | ||
| import tflite_runtime.interpreter as tflite | ||
| interpreter = tflite.Interpreter(model_path=model_path) | ||
| except ImportError: | ||
| try: | ||
| import tensorflow as tf | ||
| interpreter = tf.lite.Interpreter(model_path=model_path) | ||
| except ImportError as exc: | ||
| raise RuntimeError( | ||
| "Failed to import both tflite_runtime and tensorflow. " | ||
| "Please install either the tflite extra or tensorflow." | ||
| ) from exc | ||
|
|
||
| interpreter.allocate_tensors() | ||
| input_details = interpreter.get_input_details() | ||
| output_details = interpreter.get_output_details() | ||
|
|
||
| node = Node(args.name) | ||
| pa.array([]) | ||
|
|
||
| for event in node: | ||
| event_type = event["type"] | ||
|
|
||
| if event_type == "INPUT": | ||
| event_id = event["id"] | ||
|
|
||
| if event_id == "tensor": | ||
| storage = event["value"] | ||
| input_data = storage.to_numpy().astype(input_details[0]["dtype"]) | ||
| input_shape = input_details[0]["shape"] | ||
| input_data = input_data.reshape(input_shape) | ||
|
|
||
| interpreter.set_tensor(input_details[0]["index"], input_data) | ||
| interpreter.invoke() | ||
|
|
||
| output_data = interpreter.get_tensor(output_details[0]["index"]) | ||
| result = pa.array(output_data.ravel()) | ||
|
|
||
| node.send_output("inference", result, event["metadata"]) | ||
|
|
||
| elif event_type == "ERROR": | ||
| print(f"Received dora error: {event['error']}") | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| [project] | ||
| name = "dora-tflite" | ||
| version = "0.0.1" | ||
| authors = [ | ||
| { name = "Hari L", email = "harilogesh2019@gmail.com" }, | ||
| ] | ||
| description = "Dora Node for edge inference using TensorFlow Lite for constrained devices" | ||
| license = { text = "MIT" } | ||
| readme = "README.md" | ||
| requires-python = ">=3.9" | ||
| dependencies = [ | ||
| "dora-rs >= 0.4.0", | ||
| "numpy>=1.24.4", | ||
| ] | ||
|
|
||
| [project.optional-dependencies] | ||
| tflite = ["tflite-runtime >= 2.14.0"] | ||
|
|
||
| dev = [ | ||
| "pytest>=8.1.1", | ||
| "ruff>=0.9.1" | ||
| ] | ||
| [project.scripts] | ||
| dora-tflite = "dora_tflite.main:main" | ||
|
|
||
| [tool.ruff] | ||
| target-version = "py39" | ||
|
|
||
| [tool.ruff.lint] | ||
| select = ["E", "F", "I"] | ||
| ignore = [] |
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| """Tests for dora-tflite inference node.""" | ||
|
|
||
| import numpy as np | ||
| import pytest | ||
|
|
||
| from dora_tflite.main import main | ||
|
|
||
|
|
||
| def test_input_reshape(): | ||
| """Test that input data reshapes correctly to model input shape.""" | ||
| input_shape = [1, 224, 224, 3] | ||
| dummy_data = np.random.rand(224 * 224 * 3).astype(np.float32) | ||
| reshaped = dummy_data.reshape(input_shape) | ||
| assert reshaped.shape == tuple(input_shape) | ||
|
|
||
|
|
||
| def test_output_ravel(): | ||
| """Test that output tensor flattens correctly for pyarrow serialization.""" | ||
| dummy_output = np.array([[0.1, 0.9]], dtype=np.float32) | ||
| raveled = dummy_output.ravel() | ||
| assert len(raveled) == 2 | ||
| assert abs(raveled[0] - 0.1) < 1e-5 | ||
|
|
||
|
|
||
| def test_dtype_cast(): | ||
| """Test that input data is cast to correct dtype.""" | ||
| data = np.array([1.0, 2.0, 3.0], dtype=np.float64) | ||
| casted = data.astype(np.float32) | ||
| assert casted.dtype == np.float32 | ||
|
|
||
|
|
||
| def test_import_main(): | ||
| """Smoke test: main() should raise SystemExit or RuntimeError outside Dora dataflow.""" | ||
| with pytest.raises((SystemExit, RuntimeError)): | ||
| main() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The PR title/description focus on adding tracing to the dora-smolagents node, but this change set also introduces an entire new node package (dora-tflite) including its lockfile, tests, and docs. Please either update the PR description to cover the dora-tflite addition (and why it’s included) or split this into a separate PR to keep review scope aligned.