Skip to content

Conversation

@biswapanda
Copy link
Contributor

@biswapanda biswapanda commented Jun 16, 2025

Overview:

Fixes

  • Handle port reservation with context manager class / error handling
  • Remove unused code and bloated gpu stats

Details:

Where should the reviewer start?

Related Issues: (use one of the action keywords Closes / Fixes / Resolves / Relates to)

Summary by CodeRabbit

  • Refactor
    • Removed all GPU temperature tracking and reporting from the system.
    • Adjusted GPU statistics output to exclude temperature information.
    • Simplified port reservation with a new streamlined context manager class.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jun 16, 2025

Walkthrough

The changes remove all code related to GPU temperature tracking and reporting from the resource management modules. This includes deleting temperature attributes, methods, and log outputs associated with GPU temperature in both the GPU information and allocation logic. Only GPU utilization is now logged or reported in statistics. Additionally, the port reservation utility was simplified by replacing a complex function with a streamlined class-based context manager.

Changes

File(s) Change Summary
deploy/sdk/src/dynamo/sdk/cli/allocator.py Removed GPU temperature logging from get_resource_envs in ResourceAllocator.
deploy/sdk/src/dynamo/sdk/lib/resource.py Removed all GPU temperature handling: deleted temperature attribute, related methods, and docstrings. Removed GPUManager methods for temperature, utilization, and process tracking.
deploy/sdk/src/dynamo/sdk/cli/utils.py Replaced complex reserve_free_port function with a simpler class-based context manager PortReserver that binds to a free port and manages socket lifecycle. Removed retry and port prefix logic.
deploy/sdk/src/dynamo/sdk/cli/circus.py Added # type: ignore comment to suppress type checking on reserve_free_port() usage in get_env_or_reserved_port.

Poem

A bunny once watched GPUs run,
"Too hot?" asked the hare, "Not anymore—none!"
No temps in the logs, just utilization in view,
The code is now lighter, and simpler too.
With hops and with cheers,
The rabbit declares:
"No more degrees, just compute to share!" 🐇🔥❌


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🔭 Outside diff range comments (1)
deploy/sdk/src/dynamo/sdk/lib/resource.py (1)

140-163: 💡 Verification agent

🧩 Analysis chain

Any lingering consumers of the removed temperature field will now break

GPUInfo and get_gpu_stats() no longer expose a temperature key/attribute.
To avoid runtime KeyError/AttributeError, verify no other module still expects it.


🏁 Script executed:

#!/bin/bash
# Find any remaining usages of the old temperature field/key.
rg -n --no-heading -e '\.temperature' -e "['\"]temperature['\"]" | head

Length of output: 1112


Consumers of removed temperature field detected — update or remove references

The search uncovered multiple callsites still expecting a temperature attribute or key. These will fail at runtime with KeyError/AttributeError. Please update or remove these references, or reintroduce a default temperature field if intended.

Affected locations:

  • tests/serve/test_dynamo_serve.py:69, 76 ("temperature": 0.1 in test payloads)
  • launch/dynamo-run/src/subprocess/sglang_inc.py:57–58 (request["sampling_options"]["temperature"])
  • examples/sglang/components/worker.py:104–105 (request.sampling_options.temperature)
  • launch/dynamo-run/src/input/batch.rs:227 (.temperature(template.as_ref().map_or(0.7, |t| t.temperature)))
  • launch/dynamo-run/src/input/text.rs:105 (.temperature(template.as_ref().map_or(0.7, |t| t.temperature)))
  • examples/vllm_v0/components/worker.py:239–240 (request.sampling_options.temperature)

Recommended fixes:

  • Remove or refactor any code/tests that refer to temperature.
  • Update tests to align with the new GPUInfo schema.
  • If sampling temperature is still needed, add it back into GPUInfo (with a sensible default) or handle it upstream in the sampling logic.
🧹 Nitpick comments (2)
deploy/sdk/src/dynamo/sdk/lib/resource.py (1)

166-171: Docstring could be more explicit now that temperature is gone

The docstring still ends with the vague “etc.”.
Since this method now only updates memory, utilization and process info, tighten the wording to reflect that and avoid future confusion.

-"""Update GPU statistics (utilization, memory etc.)."""
+"""Refresh memory, utilization, and process statistics for all GPUs."""
deploy/sdk/src/dynamo/sdk/cli/allocator.py (1)

233-237: Left-over trailing space & missing comma in log string

Minor formatting cleanup:

  1. There’s an extra space just before the closing quote in the Utilization fragment.
  2. With the temperature column removed, keep the separating comma after the utilization block for consistency with earlier parts of the message.
-                                f"Utilization: {stat['gpu_utilization']}% "
+                                f"Utilization: {stat['gpu_utilization']}%,"
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ce48a86 and 50d3c02.

📒 Files selected for processing (2)
  • deploy/sdk/src/dynamo/sdk/cli/allocator.py (1 hunks)
  • deploy/sdk/src/dynamo/sdk/lib/resource.py (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Build and Test - vllm

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (2)
deploy/sdk/src/dynamo/sdk/cli/utils.py (2)

77-84: __exit__ swallows all exceptions raised during socket close.

Returning True from __exit__ suppresses any exception that occurred inside the with block, not only the ones from socket.close().
Consider limiting suppression to the close-error case:

-        except socket.error as e:
+        except socket.error as e:
             logger.warning(f"Error while closing socket: {str(e)}")
-            # Don't re-raise the exception as this is cleanup code
-            return True
+            return True  # Suppress only the close error

and leave the default None path untouched so real errors propagate.

🧰 Tools
🪛 Pylint (3.3.7)

[refactor] 77-77: Either all return statements in a function should return an expression, or none of them should.

(R1710)


61-66: Minor typing / style nits

  1. self.socket: socket.socket | None and self.port: int | None improve readability for static checkers.
  2. Consider setting SO_REUSEADDR to avoid Linux “TIME_WAIT” binding hiccups in quick succession tests.

No functional change required if resource lifetime is short.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 50d3c02 and 933aa3a.

📒 Files selected for processing (3)
  • deploy/sdk/src/dynamo/sdk/cli/allocator.py (1 hunks)
  • deploy/sdk/src/dynamo/sdk/cli/utils.py (2 hunks)
  • deploy/sdk/src/dynamo/sdk/lib/resource.py (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • deploy/sdk/src/dynamo/sdk/cli/allocator.py
  • deploy/sdk/src/dynamo/sdk/lib/resource.py
🧰 Additional context used
🪛 Pylint (3.3.7)
deploy/sdk/src/dynamo/sdk/cli/utils.py

[refactor] 77-77: Either all return statements in a function should return an expression, or none of them should.

(R1710)

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Build and Test - vllm

@biswapanda biswapanda changed the title fix: cleanup allocator fix: handle error in port reserve and cleanup allocator Jun 16, 2025
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (3)
deploy/sdk/src/dynamo/sdk/cli/utils.py (3)

61-76: PortReserver looks solid but consider enabling SO_REUSEADDR to avoid TIME_WAIT clashes

The new class nicely addresses the API-break/high-FD-leak concerns raised earlier ✅.
For long-running CLIs that reserve/release the same port repeatedly, lingering sockets in TIME_WAIT can still cause EADDRINUSE. A one-liner before bind() avoids that:

             self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+            self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)

No behaviour change for the happy path; only improves robustness on rapid restarts.


82-88: Inconsistent return paths – drop the return True from close_socket()

close_socket() returns None in the normal path but True in the error path, tripping pylint R1710 and conveying no useful information (the caller ignores the value).
Simplest fix:

-        except socket.error as e:
-            logger.warning(f"Error while closing socket: {str(e)}")
-            # Don't re-raise the exception as this is cleanup code
-            return True
+        except socket.error as e:
+            logger.warning(f"Error while closing socket: {str(e)}")
+            # Swallow cleanup errors

Now every exit path returns None, matching expectations.


91-100: Return-type annotation of reserve_free_port is misleading

With @contextlib.contextmanager applied, the function actually returns a generator-based context manager, not an AbstractContextManager[int].
Prefer one of:

-) -> contextlib.AbstractContextManager[int]:
+) -> Iterator[int]:              # simplest
# or
+) -> Generator[int, None, None]: # most explicit

This keeps static checkers (mypy/pyright) quiet and clarifies what callers receive.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 933aa3a and d9e6c57.

📒 Files selected for processing (1)
  • deploy/sdk/src/dynamo/sdk/cli/utils.py (2 hunks)
🧰 Additional context used
🪛 Pylint (3.3.7)
deploy/sdk/src/dynamo/sdk/cli/utils.py

[refactor] 81-81: Either all return statements in a function should return an expression, or none of them should.

(R1710)

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Build and Test - vllm

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
deploy/sdk/src/dynamo/sdk/cli/utils.py (1)

67-77: Optional: set SO_REUSEADDR to minimise TIME_WAIT collisions

Binding to an ephemeral port is usually fine, but on some platforms the port can remain in TIME_WAIT after close(), causing sporadic “address already in use” when the caller immediately re-binds. Adding:

self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)

just before bind() makes reuse deterministic while still reserving the port.
Low-risk, purely optional.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d9e6c57 and 9920460.

📒 Files selected for processing (2)
  • deploy/sdk/src/dynamo/sdk/cli/circus.py (1 hunks)
  • deploy/sdk/src/dynamo/sdk/cli/utils.py (2 hunks)
✅ Files skipped from review due to trivial changes (1)
  • deploy/sdk/src/dynamo/sdk/cli/circus.py
🧰 Additional context used
🪛 Pylint (3.3.7)
deploy/sdk/src/dynamo/sdk/cli/utils.py

[refactor] 81-81: Either all return statements in a function should return an expression, or none of them should.

(R1710)

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Build and Test - vllm
🔇 Additional comments (1)
deploy/sdk/src/dynamo/sdk/cli/utils.py (1)

91-100: ```shell
#!/bin/bash

List all invocations of reserve_free_port outside its definition file

rg -n 'reserve_free_port(' | grep -v 'deploy/sdk/src/dynamo/sdk/cli/utils.py'


</details>

</blockquote></details>

</details>

<!-- This is an auto-generated comment by CodeRabbit for review status -->

@biswapanda biswapanda self-assigned this Jun 17, 2025
@biswapanda biswapanda merged commit 5465f9e into main Jun 17, 2025
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants