Conversation
|
@claude review |
|
Claude: ## Summary This PR fixes memory leaks in VL (vision-language) data loading by:
The resource cleanup changes (context managers) are correct and good practice. A few concerns: IssuesWarning
Nit
VerdictCOMMENT — the core fix (context managers) is solid. The |
xtuner/v1/utils/misc.py
Outdated
| _TRIM_MEMORY_WARNED = False | ||
|
|
||
|
|
||
| def trim_memory(logger: logging.Logger | None = None): |
There was a problem hiding this comment.
logger in function arg seems weird. looks like we want to trim memory induced by logger per se. under what circumstances do we need a logger other than the global loguru logger returned by xtuner.v1.utils.get_logger?
| data_name: str | None = None, | ||
| llm_pack_weight: float = 1.0, | ||
| visual_pack_weight: float = 0.0, | ||
| trim_memory_step: int = 1, |
There was a problem hiding this comment.
might be better if we stick to trainer naming convention -- use ..._step as counter, and ..._interval for specifying frequency of doing things.
|
@claude please fix the PR as comment |
- Remove unnecessary logger parameter from trim_memory(); use global logger internally only when needed (on failure). - Rename trim_memory_step to trim_memory_interval to follow trainer naming convention (_step = counter, _interval = frequency).
|
Claude: Addressed the review comments from @nil0x9:
Changes across 3 files: New commit: hhaAndroid@4851588f |
| else: | ||
| ret = self.multi_modal_get_item(item, media_root) | ||
| if self._trim_memory_count % self._trim_memory_interval == 0: | ||
| self._trim_memory_count += 1 |
There was a problem hiding this comment.
this counter should be outside the if condition? otherwise the memory would be trimmed only once (count == 0) if trim memory interval is greater than 1?
| ret = self.calc_num_tokens_video_get_item(item) | ||
| else: | ||
| ret = self.video_get_item(item, media_root) | ||
| if self._trim_memory_count % self._trim_memory_interval == 0: |
There was a problem hiding this comment.
same issue here. incrementing should be moved outside of if clause.
| self._video_extra_info_list: list[dict] = [] | ||
|
|
||
| self._trim_memory_interval = trim_memory_interval | ||
| self._trim_memory_count = 0 |
There was a problem hiding this comment.
_trim_memory_counter might be better bc count would imply that "memory has been trimmed X times"
|
@claude address the comments in this PR and fix the code accordingly. |
This PR fixes memory leaks in VL (vision-language) data loading by: