Repository navigation
Conversation
TF's process-global GpuIdManager (virtual->physical GPU map) is written once, by the first GPU session in the process, and never updated. The per-session gpu_options.visible_device_list therefore cannot give different sessions different physical GPUs: hosting more than one per-GPU TF model in one process makes every session after the first come up without any GPU device, surfacing as 'ERR GPU requested but TF couldn't find CUDA'. Drop visible_device_list (keep allow_growth) and pin each model copy at graph-import time with TF_ImportGraphDefOptionsSetDefaultDevice, which placement honors per model. Reproduced with SmartSim 0.8 / TF 2.15 / 2x H100; see CrayLabs/SmartRedis#424.
Now that the session config no longer sets gpu_options.visible_device_list, every session sees all GPUs of the process, and the pre-existing CUDA check only proves that some GPU exists. An out-of-range index such as GPU:3 on a 2-GPU host would therefore pass AI.MODELSTORE and fail later, at AI.MODELEXECUTE, with a TensorFlow placement error. Count the GPUs returned by TF_SessionListDevices and reject deviceid >= num_gpus up front, restoring store-time validation with a message that names the actual problem instead of the old (accidental) 'ERR GPU requested but TF couldn't find CUDA'. Addresses the review finding on PR RedisAI#958.
Now that the session config no longer sets gpu_options.visible_device_list, every session sees all GPUs of the process, and the pre-existing CUDA check only proves that some GPU exists. An out-of-range index such as GPU:3 on a 2-GPU host would therefore pass AI.MODELSTORE and fail later, at AI.MODELEXECUTE, with a TensorFlow placement error. Count the GPUs returned by TF_SessionListDevices and reject deviceid >= num_gpus up front, restoring store-time validation with a message that names the actual problem instead of the old (accidental) 'ERR GPU requested but TF couldn't find CUDA'. Addresses the review finding on PR RedisAI#958 (v1.2.7 backport).
…ed GPU
TF_ImportGraphDefOptionsSetDefaultDevice only fills nodes that carry no
explicit device annotation. A node annotated /GPU:0 keeps its annotation
when the model copy is stored as GPU:1, and TF placement silently sends
it to that GPU's device 0, so per-GPU model copies would share a GPU
without any error.
After importing an indexed-GPU model, scan the graph with
TF_GraphNextOperation/TF_OperationDevice and fail at model creation if
any node is annotated with a different GPU index. The check accepts
both the modern ('/device:GPU:1') and the TF1-era lowercase ('/gpu:0')
device spellings, case-insensitively.
Graphs without node-level annotations (the freeze_graph/SavedModel
default) are unaffected.
Addresses the remaining review finding on PR RedisAI#958.
…ed GPU
TF_ImportGraphDefOptionsSetDefaultDevice only fills nodes that carry no
explicit device annotation. A node annotated /GPU:0 keeps its annotation
when the model copy is stored as GPU:1, and TF placement silently sends
it to that GPU's device 0, so per-GPU model copies would share a GPU
without any error.
After importing an indexed-GPU model, scan the graph with
TF_GraphNextOperation/TF_OperationDevice and fail at model creation if
any node is annotated with a different GPU index. The check accepts
both the modern ('/device:GPU:1') and the TF1-era lowercase ('/gpu:0')
device spellings, case-insensitively.
Graphs without node-level annotations (the freeze_graph/SavedModel
default) are unaffected.
Addresses the remaining review finding on PR RedisAI#958.
…on leak on error RAI_TFParseGpuDeviceIndex read p[1]..p[3] on every loop step, which runs past the terminating null when fewer than 4 characters remain; bail out early when the lookahead could leave the string. The cleanup path of RAI_ModelCreateTF never closed the session created by TF_NewSession, so every model-creation error after that point (including the pre-existing 'ERR GPU requested but TF couldn't find CUDA' path) leaked a fully initialized TF session. Close and delete it on cleanup. Addresses the two new review findings on PR RedisAI#958.
…on leak on error RAI_TFParseGpuDeviceIndex read p[1]..p[3] on every loop step, which runs past the terminating null when fewer than 4 characters remain; bail out early when the lookahead could leave the string. The cleanup path of RAI_ModelCreateTF never closed the session created by TF_NewSession, so every model-creation error after that point (including the pre-existing 'ERR GPU requested but TF couldn't find CUDA' path) leaked a fully initialized TF session. Close and delete it on cleanup. Addresses the two new review findings on PR RedisAI#958.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 2 potential issues.
Reviewed by Cursor Bugbot for commit c80ddb8. Configure here.
| // copies hosted by the same process. | ||
| char pinDevice[32]; | ||
| snprintf(pinDevice, sizeof(pinDevice), "/GPU:%lld", (long long)deviceid); | ||
| TF_ImportGraphDefOptionsSetDefaultDevice(options, pinDevice); |
There was a problem hiding this comment.
GPU pin breaks CPU-only operations
High Severity
TF_ImportGraphDefOptionsSetDefaultDevice writes the requested GPU onto every unannotated node, including ops that only have CPU kernels. The GPU session config still leaves allow_soft_placement at its false default, so those graphs fail at execute time on GPU:N even when they previously ran there.
Additional Locations (1)
Reviewed by Cursor Bugbot for commit c80ddb8. Configure here.
| RAI_SetError(error, RAI_EMODELIMPORT, msg); | ||
| goto cleanup; | ||
| } | ||
| } |
There was a problem hiding this comment.
Function bodies skip GPU isolation
Medium Severity
Both TF_ImportGraphDefOptionsSetDefaultDevice and the post-import conflict scan only touch top-level graph nodes. Nested FunctionDef bodies keep their original devices and are never inspected, so a GPU:1 copy can still run nested compute on GPU:0 without the new isolation error.
Additional Locations (1)
Reviewed by Cursor Bugbot for commit c80ddb8. Configure here.


Pin per-GPU TF models at graph import instead of visible_device_list
TF's process-global GpuIdManager (virtual->physical GPU map) is written once, by the first GPU session in the process, and never updated. The per-session gpu_options.visible_device_list therefore cannot give different sessions different physical GPUs: hosting more than one per-GPU TF model in one process makes every session after the first come up without any GPU device, surfacing as
'ERR GPU requested but TF couldn't find CUDA'.
Drop visible_device_list (keep allow_growth) and pin each model copy at graph-import time with TF_ImportGraphDefOptionsSetDefaultDevice, which placement honors per model.
Reproduced with SmartSim 0.8 / TF 2.15 / 2x H100; see CrayLabs/SmartRedis#424.
Note
Medium Risk
Changes TensorFlow GPU placement and model-import failure modes for all GPU models; graphs with hard-pinned GPU nodes may now be rejected where they previously loaded incorrectly.
Overview
Fixes TensorFlow models targeting different GPUs in the same process by stopping use of
gpu_options.visible_device_list(which only applies a process-global GPU map on the first session) and pinning each imported graph to the requested/GPU:NviaTF_ImportGraphDefOptionsSetDefaultDevice, while keepingallow_growthon the session.Adds
RAI_TFParseGpuDeviceIndexand a post-import scan that fails model load if any graph node has an explicit GPU device that disagrees with the requested index, avoiding silent sharing of one GPU across “per-GPU” model copies.Also validates that a requested GPU index exists when the session sees all CUDA devices, improves the cleanup path by closing/deleting a partially created session, and drops the old indexed
visible_device_listprotobuf session config.Reviewed by Cursor Bugbot for commit c80ddb8. Bugbot is set up for automated code reviews on this repo. Configure here.