Fix resource leaks, mutable default arguments, and duplicate line#183
Open
jashshah999 wants to merge 1 commit into
Open
Fix resource leaks, mutable default arguments, and duplicate line#183jashshah999 wants to merge 1 commit into
jashshah999 wants to merge 1 commit into
Conversation
- Use context managers for file writes in `inference.py` and `multiview.py` to ensure file handles are properly closed.
- Replace mutable dict defaults (`data_batch={}`, `mapping_keys={}`, `result={}`) with `None` + guard in VLM models, checkpointer, and command IPC. Mutable defaults are shared across all calls and can cause unexpected state mutations (particularly in `dcp.py` where `mapping_keys` is modified via `.update()`).
- Remove duplicate `attention_mask = data_batch.get("padding_mask", None)` line in `vlm_qwen_omni.py`.
Signed-off-by: Jash Shah <jashshah.999@gmail.com>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
Fixed resource leaks from unclosed file handles, mutable default arguments that can cause shared state mutations, and a duplicate line.
Problem
Resource leaks:
open(...).write(...)creates a file handle that is never explicitly closed, relying on garbage collection instead of deterministic cleanup.Mutable default arguments: Several functions use mutable dicts (
{}) as default parameter values. In Python, mutable defaults are shared across all calls to the function. This is particularly problematic indcp.pywheremapping_keysis modified in-place via.update()— subsequent calls without an explicit argument would see the mutations from previous calls.Duplicate line:
attention_mask = data_batch.get("padding_mask", None)appears twice consecutively invlm_qwen_omni.py.Solution
open()calls with context managers (withstatements) ininference.pyandmultiview.py.None+ guard pattern across VLM models, checkpointer, and command IPC.vlm_qwen_omni.py.