fix(exporters): scope fp16 external-data cleanup to this model (data-loss)#226
Open
rylinjames wants to merge 1 commit into
Open
fix(exporters): scope fp16 external-data cleanup to this model (data-loss)#226rylinjames wants to merge 1 commit into
rylinjames wants to merge 1 commit into
Conversation
…loss) Audit §3.3 / Part 1 #12. convert_fp32_to_fp16's pre-save cleanup globbed every `*.bin` and `*.data` file in `dst.parent` and unlinked them. The intent was only to clear leftover external data from a prior run of the model being converted — but when a user converts into a directory that also holds OTHER models' weight files (a shared export dir, a folder with an unrelated `model.onnx.data`), those get destroyed. Extracted `_remove_stale_external_data(dst)`: deletes only `.bin`/`.data` files whose name starts with `dst.stem`, never `dst` itself. Pure pathlib, so it's unit-testable without onnx/torch. Added tests/test_fp16_convert_external_data.py (5 cases): removes this model's stale .bin + legacy .data variants, preserves sibling models' weights (the data-loss guard), never unlinks dst, no-op when clean. All pass; ruff clean. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.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.
Audit §3.3 / Part 1 #12 — a real data-loss bug.
Problem
convert_fp32_to_fp16's pre-save cleanup globbed every*.binand*.dataindst.parentand unlinked them:The intent was only to clear leftover external data from a prior run of this model. But converting into a directory that also holds another model's weights (a shared export dir, an unrelated
model.onnx.data) destroys those files.Fix
Extracted
_remove_stale_external_data(dst)— deletes only.bin/.datafiles whose name starts withdst.stem, neverdstitself. Pure pathlib, unit-testable without onnx/torch.Tests
tests/test_fp16_convert_external_data.py(5 cases, all pass):.bin.data/.onnx.datavariants for this modeldstitselfruffclean on touched files.🤖 Generated with Claude Code