Skip to content

Enhance offload cleanup handling for exception cases - #2317

Open
lvliang-intel wants to merge 4 commits into
mainfrom
lvl/offload_cleanup
Open

Enhance offload cleanup handling for exception cases#2317
lvliang-intel wants to merge 4 commits into
mainfrom
lvl/offload_cleanup

Conversation

@lvliang-intel

Copy link
Copy Markdown
Contributor

Description

fix: clean up stale offload temp dirs left by killed/crashed runs.

A quantization run that is killed or crashes mid-tuning (SIGKILL, OOM-killer, host reboot) never reaches OffloadManager.cleanup(), leaving its offload temp dir under {AR_WORK_SPACE}/offload/ on disk forever. These dirs are never read by later runs, so they accumulate as pure disk waste.

This PR makes new runs automatically remove leftovers from dead processes, without ever touching data owned by live processes.

Type of Change

Bug fix

Related Issues

None

Checklist Before Submitting

  • My code has been tested locally.
  • Documentation has been updated as needed.
  • New or updated tests are included where applicable.
  • The CUDA CI has passed. You can trigger it by commenting /azp run Unit-Test-CUDA-AutoRound.

@AutoRoundBot

Copy link
Copy Markdown
Collaborator

/azp run Unit-Test-CUDA-AutoRound

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@AutoRoundBot

Copy link
Copy Markdown
Collaborator

/azp run Unit-Test-CUDA-AutoRound

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The new sweep logic can fail under races (base dir removed mid-sweep) and doesn’t handle out-of-range PIDs safely, and the new test helper’s path lowercasing can leak temp dirs on case-sensitive filesystems.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

This PR fixes disk waste from killed/crashed quantization runs by making OffloadManager proactively remove stale, PID-tagged offload temp directories during startup, while preserving resume and legacy directories.

Changes:

  • PID-tags newly created offload temp dirs and sweeps dead-PID dirs before creating a new one.
  • Adds _pid_alive() and _sweep_stale_dirs() helpers to safely detect and remove stale directories.
  • Introduces unit tests covering stale-dir removal, live/resume preservation, and “no sweep in resume mode”.
File summaries
File Description
auto_round/utils/offload.py Adds stale offload dir sweeping + PID-tagged tempdir naming.
test/unit/common/utils/test_offload_helpers.py Adds unit tests validating sweep behavior across stale/live/resume/legacy cases.
Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 3
  • Review effort level: Lite

💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +913 to +918
try:
os.kill(pid, 0)
except ProcessLookupError:
return False # no such process
except OSError:
return True # e.g. PermissionError -> exists, owned by another user
Comment on lines +923 to +927
if not os.path.isdir(base_dir):
return
tag = f"{self._prefix}_"
for entry in sorted(os.listdir(base_dir)):
full = os.path.join(base_dir, entry)
Comment on lines +272 to +278
def _offload_base(self, tmp_path, monkeypatch) -> str:
workspace = str(tmp_path).lower() # envs.AR_WORK_SPACE is lowercased
monkeypatch.setenv("AR_WORK_SPACE", workspace)
monkeypatch.delenv("AR_RESUME_DIR", raising=False)
base = os.path.join(workspace, "offload")
os.makedirs(base, exist_ok=True)
return base
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants