@@ -1267,10 +1267,10 @@ def load_gpu_shapes_index(
12671267 auth : Optional [Dict [str , Any ]] = None ,
12681268) -> GPUShapesIndex :
12691269 """
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 .
12711271
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 .
12741274
12751275 Parameters
12761276 ----------
@@ -1291,7 +1291,9 @@ def load_gpu_shapes_index(
12911291 file_name = "gpu_shapes_index.json"
12921292
12931293 # Try remote load
1294- remote_data : Dict [str , Any ] = {}
1294+ local_data , remote_data = {}, {}
1295+ local_mtime , remote_mtime = None , None
1296+
12951297 if CONDA_BUCKET_NS :
12961298 try :
12971299 auth = auth or authutil .default_signer ()
@@ -1301,8 +1303,24 @@ def load_gpu_shapes_index(
13011303 logger .debug (
13021304 "Loading GPU shapes index from Object Storage: %s" , storage_path
13031305 )
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 :
13051309 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+
13061324 logger .debug (
13071325 "Loaded %d shapes from Object Storage" ,
13081326 len (remote_data .get ("shapes" , {})),
@@ -1311,12 +1329,19 @@ def load_gpu_shapes_index(
13111329 logger .debug ("Remote load failed (%s); falling back to local" , ex )
13121330
13131331 # Load local copy
1314- local_data : Dict [str , Any ] = {}
13151332 local_path = os .path .join (os .path .dirname (__file__ ), "../resources" , file_name )
13161333 try :
13171334 logger .debug ("Loading GPU shapes index from local file: %s" , local_path )
13181335 with open (local_path ) as f :
13191336 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+
13201345 logger .debug (
13211346 "Loaded %d shapes from local file" , len (local_data .get ("shapes" , {}))
13221347 )
@@ -1326,7 +1351,24 @@ def load_gpu_shapes_index(
13261351 # Merge: remote shapes override local
13271352 local_shapes = local_data .get ("shapes" , {})
13281353 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 = {}
13301372
13311373 return GPUShapesIndex (shapes = merged_shapes )
13321374
0 commit comments