b10-transfer 0.1.2__py3-none-any.whl → 0.1.3__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
b10_transfer/__init__.py CHANGED
@@ -7,7 +7,7 @@ from .info import get_cache_info, list_available_caches
7
7
  from .constants import SaveStatus, LoadStatus
8
8
 
9
9
  # Version
10
- __version__ = "0.1.2"
10
+ __version__ = "0.1.3"
11
11
 
12
12
  __all__ = [
13
13
  "CacheError",
b10_transfer/constants.py CHANGED
@@ -129,3 +129,10 @@ class SaveStatus(Enum):
129
129
  SUCCESS = auto()
130
130
  ERROR = auto()
131
131
  SKIPPED = auto()
132
+
133
+
134
+ class TransferStatus(Enum):
135
+ """Status values for file transfer operations."""
136
+
137
+ SUCCESS = auto()
138
+ ERROR = auto()
b10_transfer/core.py CHANGED
@@ -35,6 +35,7 @@ from .constants import (
35
35
  CACHE_INCOMPLETE_SUFFIX,
36
36
  LoadStatus,
37
37
  SaveStatus,
38
+ TransferStatus,
38
39
  )
39
40
 
40
41
  logger = logging.getLogger(__name__)
@@ -286,6 +287,90 @@ def save_compile_cache() -> SaveStatus:
286
287
  space_monitor.stop()
287
288
 
288
289
 
290
+ @timed_fn(logger=logger, name="Transferring file")
291
+ @safe_execute("Transfer failed", TransferStatus.ERROR)
292
+ def transfer(source: str, dest: str) -> TransferStatus:
293
+ """Transfer a file from source to destination with space monitoring.
294
+
295
+ This function copies a file from source to destination using the same
296
+ monitored process approach as the cache operations. It monitors disk space
297
+ at the destination and can interrupt the transfer if space becomes insufficient.
298
+
299
+ Args:
300
+ source: Path to the source file to copy.
301
+ dest: Path to the destination where the file will be copied.
302
+
303
+ Returns:
304
+ TransferStatus:
305
+ TransferStatus.SUCCESS if transfer was successful
306
+ TransferStatus.ERROR if transfer failed due to insufficient disk space,
307
+ file not found, or other errors.
308
+
309
+ Raises:
310
+ CacheOperationInterrupted: If transfer interrupted due to insufficient
311
+ disk space (caught and returns TransferStatus.ERROR).
312
+ Exception: Any other errors during transfer (caught and returns TransferStatus.ERROR).
313
+ """
314
+ source_path = Path(source)
315
+ dest_path = Path(dest)
316
+
317
+ # Validate source file exists
318
+ if not source_path.exists():
319
+ logger.error(f"Source file does not exist: {source}")
320
+ return TransferStatus.ERROR
321
+
322
+ # Create destination directory if it doesn't exist
323
+ dest_path.parent.mkdir(parents=True, exist_ok=True)
324
+
325
+ # Determine appropriate space threshold based on destination directory
326
+ dest_dir = dest_path.parent
327
+ if str(dest_dir).startswith(B10FS_CACHE_DIR):
328
+ # Transferring to b10fs - use b10fs space requirements
329
+ space_threshold_mb = REQUIRED_B10FS_SPACE_MB
330
+ logger.debug(
331
+ f"Transfer to b10fs detected, using {space_threshold_mb:.1f}MB threshold"
332
+ )
333
+ else:
334
+ # Transferring to local directory - use local space requirements
335
+ space_threshold_mb = MIN_LOCAL_SPACE_MB
336
+ logger.debug(
337
+ f"Transfer to local directory detected, using {space_threshold_mb:.1f}MB threshold"
338
+ )
339
+
340
+ # Initial disk space check
341
+ check_sufficient_disk_space(dest_dir, space_threshold_mb, "file transfer")
342
+ logger.debug(
343
+ f"Initial space check passed: {space_threshold_mb:.1f}MB required at destination"
344
+ )
345
+
346
+ # Start background space monitoring for destination directory
347
+ space_monitor = CacheSpaceMonitor(space_threshold_mb, dest_dir)
348
+ space_monitor.start()
349
+
350
+ try:
351
+ # Run monitored copy process
352
+ logger.info(f"Starting transfer: {source} -> {dest}")
353
+ run_monitored_process(
354
+ _cache_copy_worker,
355
+ (str(source_path), str(dest_path)),
356
+ space_monitor,
357
+ "file transfer",
358
+ cleanup_func=lambda: safe_unlink(
359
+ dest_path, f"Failed to cleanup interrupted transfer {dest_path}"
360
+ ),
361
+ )
362
+
363
+ logger.info("File transfer complete")
364
+ return TransferStatus.SUCCESS
365
+
366
+ except CacheOperationInterrupted as e:
367
+ logger.warning(f"File transfer interrupted: {e}")
368
+ return TransferStatus.ERROR
369
+
370
+ finally:
371
+ space_monitor.stop()
372
+
373
+
289
374
  @safe_execute("Clear failed", False)
290
375
  def clear_local_cache() -> bool:
291
376
  """Clear the local PyTorch compilation cache directory.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: b10-transfer
3
- Version: 0.1.2
3
+ Version: 0.1.3
4
4
  Summary: Distributed PyTorch file transfer for Baseten - Environment-aware, lock-free file transfer management
5
5
  License: MIT
6
6
  Keywords: pytorch,file-transfer,cache,machine-learning,inference
@@ -1,12 +1,12 @@
1
- b10_transfer/__init__.py,sha256=kZXd7GHMH7PFzr4aXs19MmuFzwEvtwzh0rwyK4jHgHo,641
1
+ b10_transfer/__init__.py,sha256=qaqigpp3gmzR4-Cr9aH1ilaYQgp9UB_DzzpsmwX_D-o,641
2
2
  b10_transfer/archive.py,sha256=GKb0mi0-YeM7ch4FLAoOLHXw0T6LkRerYad2N2y9TYM,6400
3
3
  b10_transfer/cleanup.py,sha256=3RnqWNGMCcko5GQdq1Gr9VPpGzAF5J6x7xjIH9SNZ78,6226
4
- b10_transfer/constants.py,sha256=EmWCh9AOamCZL3KkSU6YJO6KBkh93OmAIUeEfaZxHL0,4321
5
- b10_transfer/core.py,sha256=tKA1gWDEpcb_Xfr6njScAGWCxIT3htlyVh9VLg67YMg,15445
4
+ b10_transfer/constants.py,sha256=qCViKTyfHTLpiFVF2SwsbHp2IMz3kg3syxJfgRAq2dc,4446
5
+ b10_transfer/core.py,sha256=UVjzcqCqDMqpXqiXzdC6c8nJ_2tM35zlDl-Jp1Gvn20,18657
6
6
  b10_transfer/environment.py,sha256=aC0biEMQrtHk0ke_3epdcq1X9J5fPmPpBVt0fH7XF2Y,5625
7
7
  b10_transfer/info.py,sha256=I3iOuImZ5r6DMJTDeBtVvzlSn6IuyPJbLJYUO_OF0ks,6299
8
8
  b10_transfer/space_monitor.py,sha256=C_CKDH43bNsWdq60WStSZ3c_nQkWvScQmqU_SYHesew,10531
9
9
  b10_transfer/utils.py,sha256=Stee0DFK-8MRRYNIocqaK64cJvfs4jPW3Mpx7zkWV6Y,11932
10
- b10_transfer-0.1.2.dist-info/METADATA,sha256=P0Yf1VzkqFV4eco8x1yAjgUiahlmjgJGTAee0NNhh6o,4108
11
- b10_transfer-0.1.2.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
12
- b10_transfer-0.1.2.dist-info/RECORD,,
10
+ b10_transfer-0.1.3.dist-info/METADATA,sha256=dNTL7He36x0j9nZpbf5Rhaa4FYHeuNaim2zyXCKq_lE,4108
11
+ b10_transfer-0.1.3.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
12
+ b10_transfer-0.1.3.dist-info/RECORD,,