@@ -1267,10 +1267,10 @@ def load_gpu_shapes_index(
1267
1267
auth : Optional [Dict [str , Any ]] = None ,
1268
1268
) -> GPUShapesIndex :
1269
1269
"""
1270
- Load the GPU shapes index, preferring the OS bucket copy over the local one .
1270
+ Load the GPU shapes index, merging based on freshness .
1271
1271
1272
- Attempts to read `gpu_shapes_index.json` from OCI Object Storage first;
1273
- if that succeeds, those entries will override the local defaults .
1272
+ Compares last-modified timestamps of local and remote files,
1273
+ merging the shapes from the fresher file on top of the older one .
1274
1274
1275
1275
Parameters
1276
1276
----------
@@ -1291,7 +1291,9 @@ def load_gpu_shapes_index(
1291
1291
file_name = "gpu_shapes_index.json"
1292
1292
1293
1293
# Try remote load
1294
- remote_data : Dict [str , Any ] = {}
1294
+ local_data , remote_data = {}, {}
1295
+ local_mtime , remote_mtime = None , None
1296
+
1295
1297
if CONDA_BUCKET_NS :
1296
1298
try :
1297
1299
auth = auth or authutil .default_signer ()
@@ -1301,8 +1303,24 @@ def load_gpu_shapes_index(
1301
1303
logger .debug (
1302
1304
"Loading GPU shapes index from Object Storage: %s" , storage_path
1303
1305
)
1304
- with fsspec .open (storage_path , mode = "r" , ** auth ) as f :
1306
+
1307
+ fs = fsspec .filesystem ("oci" , ** auth )
1308
+ with fs .open (storage_path , mode = "r" ) as f :
1305
1309
remote_data = json .load (f )
1310
+
1311
+ remote_info = fs .info (storage_path )
1312
+ remote_mtime_str = remote_info .get ("timeModified" , None )
1313
+ if remote_mtime_str :
1314
+ # Convert OCI timestamp (e.g., 'Mon, 04 Aug 2025 06:37:13 GMT') to epoch time
1315
+ remote_mtime = datetime .strptime (
1316
+ remote_mtime_str , "%a, %d %b %Y %H:%M:%S %Z"
1317
+ ).timestamp ()
1318
+
1319
+ logger .debug (
1320
+ "Remote GPU shapes last-modified time: %s" ,
1321
+ datetime .fromtimestamp (remote_mtime ).strftime ("%Y-%m-%d %H:%M:%S" ),
1322
+ )
1323
+
1306
1324
logger .debug (
1307
1325
"Loaded %d shapes from Object Storage" ,
1308
1326
len (remote_data .get ("shapes" , {})),
@@ -1311,12 +1329,19 @@ def load_gpu_shapes_index(
1311
1329
logger .debug ("Remote load failed (%s); falling back to local" , ex )
1312
1330
1313
1331
# Load local copy
1314
- local_data : Dict [str , Any ] = {}
1315
1332
local_path = os .path .join (os .path .dirname (__file__ ), "../resources" , file_name )
1316
1333
try :
1317
1334
logger .debug ("Loading GPU shapes index from local file: %s" , local_path )
1318
1335
with open (local_path ) as f :
1319
1336
local_data = json .load (f )
1337
+
1338
+ local_mtime = os .path .getmtime (local_path )
1339
+
1340
+ logger .debug (
1341
+ "Local GPU shapes last-modified time: %s" ,
1342
+ datetime .fromtimestamp (local_mtime ).strftime ("%Y-%m-%d %H:%M:%S" ),
1343
+ )
1344
+
1320
1345
logger .debug (
1321
1346
"Loaded %d shapes from local file" , len (local_data .get ("shapes" , {}))
1322
1347
)
@@ -1326,7 +1351,24 @@ def load_gpu_shapes_index(
1326
1351
# Merge: remote shapes override local
1327
1352
local_shapes = local_data .get ("shapes" , {})
1328
1353
remote_shapes = remote_data .get ("shapes" , {})
1329
- merged_shapes = {** local_shapes , ** remote_shapes }
1354
+ merged_shapes = {}
1355
+
1356
+ if local_mtime and remote_mtime :
1357
+ if remote_mtime >= local_mtime :
1358
+ logger .debug ("Remote data is fresher or equal; merging remote over local." )
1359
+ merged_shapes = {** local_shapes , ** remote_shapes }
1360
+ else :
1361
+ logger .debug ("Local data is fresher; merging local over remote." )
1362
+ merged_shapes = {** remote_shapes , ** local_shapes }
1363
+ elif remote_shapes :
1364
+ logger .debug ("Only remote shapes available." )
1365
+ merged_shapes = remote_shapes
1366
+ elif local_shapes :
1367
+ logger .debug ("Only local shapes available." )
1368
+ merged_shapes = local_shapes
1369
+ else :
1370
+ logger .error ("No GPU shapes data found in either source." )
1371
+ merged_shapes = {}
1330
1372
1331
1373
return GPUShapesIndex (shapes = merged_shapes )
1332
1374
0 commit comments