mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-08-21 08:14:00 +08:00
Revert "safer model pkl chunking (#37283)"
This reverts commit 5d54743d8b.
This commit is contained in:
+5
-10
@@ -1,9 +1,8 @@
|
||||
import glob
|
||||
import math
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
CHUNK_SIZE = 19 * 1024 * 1024 # 49MB, under GitHub's 50MB limit
|
||||
CHUNK_SIZE = 49 * 1024 * 1024 # 49MB, under GitHub's 50MB limit
|
||||
|
||||
def get_chunk_name(name, idx, num_chunks):
|
||||
return f"{name}.chunk{idx+1:02d}of{num_chunks:02d}"
|
||||
@@ -13,8 +12,6 @@ def get_chunk_paths(path, file_size):
|
||||
return [get_chunk_name(path, i, num_chunks) for i in range(num_chunks)]
|
||||
|
||||
def chunk_file(path, num_chunks):
|
||||
for old in glob.glob(f"{path}.chunk*"):
|
||||
os.remove(old)
|
||||
with open(path, 'rb') as f:
|
||||
data = f.read()
|
||||
actual_num_chunks = max(1, math.ceil(len(data) / CHUNK_SIZE))
|
||||
@@ -22,15 +19,13 @@ def chunk_file(path, num_chunks):
|
||||
for i in range(num_chunks):
|
||||
with open(get_chunk_name(path, i, num_chunks), 'wb') as f:
|
||||
f.write(data[i * CHUNK_SIZE:(i + 1) * CHUNK_SIZE])
|
||||
os.remove(path)
|
||||
|
||||
|
||||
def read_file_chunked(path):
|
||||
chunks = sorted(glob.glob(f"{path}.chunk*"))
|
||||
if chunks:
|
||||
expected = [get_chunk_name(path, i, len(chunks)) for i in range(len(chunks))]
|
||||
assert chunks == expected, f"Chunk mismatch: {chunks} != {expected}"
|
||||
return b''.join(Path(f).read_bytes() for f in chunks)
|
||||
for num_chunks in range(1, 100):
|
||||
if os.path.isfile(get_chunk_name(path, 0, num_chunks)):
|
||||
files = [get_chunk_name(path, i, num_chunks) for i in range(num_chunks)]
|
||||
return b''.join(Path(f).read_bytes() for f in files)
|
||||
if os.path.isfile(path):
|
||||
return Path(path).read_bytes()
|
||||
raise FileNotFoundError(path)
|
||||
|
||||
Reference in New Issue
Block a user