FIX: never feed a suspect GGUF to GGUFReader (its traceback keeps the fd open after unlink) + free-space gate
Browse filesA dead GGUFReader stayed alive inside Jupyter's sys.last_traceback, so the deleted 5.3 GiB partial mix held its blocks and the disk stayed at 100% with 136 KB free. Now the bundle checks the magic with a plain open() before touching GGUFReader, asserts >3 GB free before quantizing, and names the traceback mechanism in the assert. The runner releases sys.last_traceback and gc.collect()s before hygiene so deleted space is actually reclaimed.
- UPLOAD_1_trnr_ship.py +18 -0
UPLOAD_1_trnr_ship.py
CHANGED
|
@@ -944,6 +944,24 @@ if not (os.path.isfile(PP) and os.path.isfile(QF)):
|
|
| 944 |
# as the nthreads positional ("invalid nthread '--tensor-type'").
|
| 945 |
F16GG = BASE
|
| 946 |
MIX = K + "/trnr-mix.gguf"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 947 |
if not os.path.exists(MIX):
|
| 948 |
NT = str(os.cpu_count() or 4)
|
| 949 |
ok = False
|
|
|
|
| 944 |
# as the nthreads positional ("invalid nthread '--tensor-type'").
|
| 945 |
F16GG = BASE
|
| 946 |
MIX = K + "/trnr-mix.gguf"
|
| 947 |
+
if os.path.exists(MIX):
|
| 948 |
+
# NEVER hand a suspect file to GGUFReader: if it raises, the half-built reader stays alive
|
| 949 |
+
# inside Jupyter's sys.last_traceback and the file object stays OPEN -- an unlinked-then-
|
| 950 |
+
# deleted 5 GB file then holds its blocks until the kernel is restarted. Check the magic
|
| 951 |
+
# with a plain open() instead, which closes immediately.
|
| 952 |
+
with open(MIX, "rb") as _fh:
|
| 953 |
+
_magic = _fh.read(4)
|
| 954 |
+
if _magic != b"GGUF":
|
| 955 |
+
P("freeing %.2f GB: %s has magic %r -- not a finished GGUF (a quantize that died mid-write)"
|
| 956 |
+
% (os.path.getsize(MIX) / 1e9, os.path.basename(MIX), _magic))
|
| 957 |
+
os.remove(MIX)
|
| 958 |
+
_st = os.statvfs(K)
|
| 959 |
+
_avail = _st.f_bavail * _st.f_frsize
|
| 960 |
+
P("%.2f GB free before the quantize" % (_avail / 1e9))
|
| 961 |
+
assert _avail > 3.0e9, ("only %.2f GB free and the quantize needs ~2.5 GB. If files were just "
|
| 962 |
+
"deleted, something still holds them open: Jupyter tracebacks keep fds "
|
| 963 |
+
"alive. Re-run the runner cell (it clears sys.last_traceback) or restart "
|
| 964 |
+
"the kernel." % (_avail / 1e9))
|
| 965 |
if not os.path.exists(MIX):
|
| 966 |
NT = str(os.cpu_count() or 4)
|
| 967 |
ok = False
|