-
Notifications
You must be signed in to change notification settings - Fork 293
wandb weave tracing integration #270
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
ropresearch
wants to merge
20
commits into
main
Choose a base branch
from
rop/weave
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 15 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
b379dbc
wandb weave tracing integration
ropresearch 6f169bb
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] e122194
precommit format fixes
ropresearch 6de15ab
Merge branch 'rop/weave' of https://github.com/NousResearch/atropos i…
ropresearch 5c34f48
documentation updates
ropresearch f5da18f
reverted weave ops, only for base env completions tracing
ropresearch 62fa2ab
format and weave cleanup
ropresearch 2df4ee9
Update to allow tracing flag through config
ropresearch 0179b25
zmq message passing & env data aggregation for wandb
ropresearch 646da3a
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] f58c927
decoupled zmq from server through run-api cli command subprocess
ropresearch 03cc5e3
Merge branch 'rop/zmq-message-pass' of https://github.com/NousResearc…
ropresearch e2fe5e7
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 735c14f
Merge pull request #282 from NousResearch/rop/zmq-message-pass
ropresearch 0050d1f
Merge branch 'main' into rop/weave
ropresearch d1bcadc
tag fixes and ZMQ change for better env categorization
ropresearch f28c344
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] d227d9a
env controlled wandb log pushes
ropresearch fba8922
Merge remote rop/weave, resolve sidecar conflicts
ropresearch 7654e3d
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,132 @@ | ||
| import argparse | ||
| import logging | ||
| import threading | ||
| from typing import Any, Dict, Optional | ||
|
|
||
| import wandb | ||
| import zmq | ||
|
|
||
| # Configure logging | ||
| logging.basicConfig( | ||
| level=logging.INFO, | ||
| format="%(asctime)s - %(name)s - %(levelname)s - %(message)s", | ||
| ) | ||
| logger = logging.getLogger("ZMQSidecar") | ||
|
|
||
|
|
||
| class ZMQLogAggregator: | ||
| """ | ||
| A sidecar service that listens for log data over ZeroMQ and aggregates it | ||
| into the centralized WandB run. | ||
| """ | ||
|
|
||
| def __init__(self, port: int = 5555, context: Optional[zmq.Context] = None): | ||
| self.port = port | ||
| self.context = context or zmq.Context() | ||
| self.socket = self.context.socket(zmq.PULL) | ||
| self.running = False | ||
| self.thread = None | ||
|
|
||
| def start(self): | ||
| """Start the aggregator thread.""" | ||
| if self.running: | ||
| return | ||
|
|
||
| try: | ||
| self.socket.bind(f"tcp://*:{self.port}") | ||
| logger.info(f"ZMQLogAggregator listening on port {self.port}") | ||
| except zmq.ZMQError as e: | ||
| logger.error(f"Failed to bind ZMQ socket on port {self.port}: {e}") | ||
| raise | ||
|
|
||
| self.running = True | ||
| # In process mode, we run directly, not in a thread | ||
| self._loop() | ||
|
|
||
| def stop(self): | ||
| """Stop the aggregator.""" | ||
| self.running = False | ||
| try: | ||
| self.socket.close() | ||
| except Exception: | ||
| pass | ||
|
|
||
| def _handle_control_message(self, payload: Dict[str, Any]): | ||
| """Handle control messages for lifecycle management.""" | ||
| msg_type = payload.get("_type") | ||
|
|
||
| if msg_type == "init": | ||
| config = payload.get("config", {}) | ||
| logger.info( | ||
| f"Received INIT command. Starting WandB run: {config.get('group', 'unknown')}" | ||
| ) | ||
|
|
||
| # Make sure we finish any existing run | ||
| if wandb.run is not None: | ||
| logger.info("Finishing existing WandB run before starting new one") | ||
| wandb.finish() | ||
|
|
||
| try: | ||
| wandb.init(**config) | ||
| logger.info(f"WandB run initialized: {wandb.run.id}") | ||
| except Exception as e: | ||
| logger.error(f"Failed to initialize WandB: {e}") | ||
|
|
||
| elif msg_type == "reset": | ||
| logger.info("Received RESET command. Finishing WandB run.") | ||
| if wandb.run is not None: | ||
| wandb.finish() | ||
| else: | ||
| logger.info("No active WandB run to finish.") | ||
|
|
||
| def _loop(self): | ||
| """Main listening loop.""" | ||
| poller = zmq.Poller() | ||
| poller.register(self.socket, zmq.POLLIN) | ||
|
|
||
| logger.info("ZMQ Sidecar loop started") | ||
|
|
||
| while self.running: | ||
| try: | ||
| # check if open | ||
| socks = dict(poller.poll(1000)) | ||
| if self.socket in socks: | ||
| # pyobj in case of some other data stuff later | ||
| payload = self.socket.recv_pyobj() | ||
|
|
||
| # Check if it's a control message | ||
| if isinstance(payload, dict) and "_type" in payload: | ||
| self._handle_control_message(payload) | ||
| continue | ||
|
|
||
| # Otherwise treat as log payload | ||
| if wandb.run is not None: | ||
| wandb.log(payload) | ||
| else: | ||
| # Optional: accumulate logs buffer or just debug log | ||
| # For now, we just debug log to avoid memory leaks | ||
| pass | ||
| # logger.debug("Received log payload (wandb not active)") | ||
|
|
||
| except Exception as e: | ||
| logger.error(f"Error in ZMQLogAggregator loop: {e}") | ||
| # Don't break on transient errors, but logging essential | ||
| # if not self.running: | ||
| # break | ||
|
|
||
|
|
||
| def main(): | ||
| parser = argparse.ArgumentParser(description="Atropos ZMQ Logging Sidecar") | ||
| parser.add_argument("--port", type=int, default=5555, help="Port to listen on") | ||
| args = parser.parse_args() | ||
|
|
||
| aggregator = ZMQLogAggregator(port=args.port) | ||
| try: | ||
| aggregator.start() | ||
| except KeyboardInterrupt: | ||
| logger.info("Stopping ZMQ Sidecar...") | ||
| aggregator.stop() | ||
|
|
||
|
|
||
| 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
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.
this should not be controlled here, it should be routed back to the environment
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.
you will also need logic to wait for all connected environments to figure out when to send it back