[Bug] CUBLAS_STATUS_INVALID_VALUE on RTX 4090 (torch==1.12.1) for CLIP & matmul in Grounding_3D
Environment
- OS: Linux (cluster server)
- GPU: NVIDIA GeForce RTX 4090 (Ada)
- CUDA (system): 11.8
- Python: 3.8 (conda)
- Main packages (almost identical to the repo’s
environment.yaml):torch==1.12.1torchvision==0.13.1torchaudio==0.12.1open_clip_torch==2.29.0gsplat==1.4.0pytorch3d==0.7.5- Other dependencies are very close to those in
environment.yaml(fullpip listavailable if needed)
Under this environment, when I try to reproduce COS3D (e.g., scene figurines) on RTX 4090 + torch 1.12.1, I consistently hit the same type of error:
Whenever certain matrix multiplications are executed on the GPU, I get
CUBLAS_STATUS_INVALID_VALUE, while the exact same operations on CPU run without any issue.
Error 1: open_clip encode_text
Minimal repro code:
import torch, open_clip
device = "cuda"
model, _, _ = open_clip.create_model_and_transforms(
"ViT-B-32", pretrained="laion2b_s34b_b79k"
)
model = model.to(device)
tokenizer = open_clip.get_tokenizer("ViT-B-32")
tok = tokenizer(["a photo of a cat"]).to(device)
with torch.no_grad():
feat = model.encode_text(tok)
On RTX 4090 + torch 1.12.1, this fails at encode_text with:
RuntimeError: CUDA error: CUBLAS_STATUS_INVALID_VALUE when calling `cublasSgemm(...)`
If I change to device="cpu", the exact same code runs successfully.
Error 2: Grounding_3D.Instance2Language_kernel matmul
In Grounding_3D.py, inside Instance2Language_kernel:
@torch.no_grad()
def Instance2Language_kernel(feature_obj, CLIP_pair):
anchor_feature = CLIP_pair['feature'] # [7249, 16]
anchor_clip = CLIP_pair['clip'] # [7249, 512]
print("feature_obj:", feature_obj.shape, feature_obj.dtype, feature_obj.device)
print("anchor_feature:", anchor_feature.shape, anchor_feature.dtype, anchor_feature.device)
for i in range(0, feature_obj.shape[0], chunksize):
distances = 1 - torch.matmul(feature_obj[i:i+chunksize], anchor_feature.T)
Debug prints:
feature_obj: torch.Size([954709, 16]) torch.float32 cuda:0
anchor_feature: torch.Size([7249, 16]) torch.float32 cuda:0
Mathematically this is [chunk, 16] @ [16, 7249], so shape/dtype/device all look valid, but the line still throws:
RuntimeError: CUDA error: CUBLAS_STATUS_INVALID_VALUE when calling `cublasSgemm(...)`
If I move the same computation to CPU (feature_obj.cpu() @ anchor_feature.cpu().T), it runs fine.
Error 3: torch.mm in eval/openclip_encoder.py
In eval/openclip_encoder.py, both get_relevancy and get_semantic_map show the same behavior. Example:
@torch.no_grad()
def get_relevancy(self, embed, positive_id):
phrases_embeds = torch.cat([self.pos_embeds, self.neg_embeds], dim=0)
p = phrases_embeds.to(embed.dtype)
output = torch.mm(embed, p.T) # This triggers the CUBLAS error on GPU
Here embed and p are shapes like [N, 512], dtype=float32, both on cuda:0.
But running torch.mm on GPU raises CUBLAS_STATUS_INVALID_VALUE.
If I change it to embed.cpu() @ p.cpu().T, it works fine on CPU.
Current workaround
To finish the reproduction of the paper, I applied the following changes:
-
OpenCLIP part
- Keep the
OpenCLIPNetworkmodel on CPU (precision="fp32"). - Run all
encode_text/encode_imagecalls on CPU, then move the resulting embeddings to CUDA with.to(cuda).
- Keep the
-
Grounding_3D.Instance2Language_kernel-
Copy
feature_obj/anchor_feature/anchor_clipto CPU:feature_obj_cpu = feature_obj.detach().cpu().float() anchor_feature_cpu = anchor_feature.detach().cpu().float() anchor_clip_cpu = anchor_clip.detach().cpu().float() -
Perform all
matmul/topk/ weighted averaging on CPU. -
After obtaining
matching_CLIP_3D, move it back tofeature_obj.device(cuda).
-
-
openclip_encoder.get_relevancy/get_semantic_map- Run the internal
torch.mmcalls on CPU as well:embed_cpu = embed.detach().cpu().float()phrases_embeds_cpu = ...detach().cpu().float()
- Do softmax + argmax on CPU, then move the results back to the original device.
- Run the internal
After these changes:
- All
CUBLAS_STATUS_INVALID_VALUEerrors disappeared. - 3D grounding, rendering, and metric computation can finish successfully.
- The only downside is that CLIP-related parts are slower, but overall runtime is still acceptable.
Questions
- Has this repo been tested with Ada GPUs (e.g. RTX 4090) + torch==1.12.1?
- Do you have an officially recommended PyTorch / CUDA configuration that is known to work reliably on RTX 4090 for this project?
- Would you consider:
- Adding a note in the README or
environment.yamlthat torch 1.12.1 may be problematic on newer GPUs like RTX 4090, and/or - Providing an updated environment (e.g. PyTorch 2.x + cu118/cu121) better suited for Ada GPUs?
- Adding a note in the README or
If it would be helpful, I’m happy to clean up my CPU fallback changes and open a small PR to add them as an optional compatibility mode.
Sorry, I have not encountered this issue. Could you test your PyTorch environment first? It seems that your PyTorch setup might not be working correctly. For example, torch.mm is a basic operation and should definitely work well in CUDA mode.
Sorry, I have not encountered this issue. Could you test your PyTorch environment first? It seems that your PyTorch setup might not be working correctly. For example, torch.mm is a basic operation and should definitely work well in CUDA mode.
Thank you very much for your response. We have now successfully resolved the issue. As mentioned in our previous message, we had already analyzed the root cause. Trusting the YAML configuration you provided, we refrained from modifying any environment settings. Instead, we migrated all operations that were incompatible with torch.mm to the CPU, which initially allowed us to run the instance_train stage successfully—an encouraging outcome at the time. However, fully redirecting all torch.mm operations to the CPU led to a more severe issue: although the training process could proceed, the model failed to converge. During final evaluation, all metrics were zero. After carefully inspecting each step, we found through PCA-based dimensionality reduction visualizations that the instance segmentation component exhibited no convergence behavior. This unexpected outcome was deeply discouraging and almost led us to abandon the effort. Your supportive reply greatly boosted our confidence. We highly value the reliability of your code and the clarity of the README instructions. Upon a complete review, we confirmed that our only modification involved handling the incompatibility between the RTX 4090 GPU and torch==1.12.1, which affected certain computational steps. We then repeated the entire pipeline without any code modifications, resolving the compatibility issues by upgrading to torch 2.0.1 + cu118 and ensuring the consistency of all related packages. Encouragingly, this time we successfully reproduced the results, obtaining performance closely aligned with those reported in your paper. Once again, we thank you for your support. This is an impressive piece of work, and we look forward to seeing more of your future research.
Below are details of the fix we made regarding the incompatibility issue between the torch version and the RTX 4090 GPU version.
Description
On RTX 4090 (Ada, SM 8.9), the repo’s provided environment (torch 1.12.1 + CUDA 11.3) fails with:
RuntimeError: CUDA error: CUBLAS_STATUS_INVALID_VALUE (cublasSgemm).
This is an environment/compatibility issue: even a minimal CUDA matmul fails.
Minimal repro (fails in original env)
python - <<'PY'
import torch
print("torch", torch.__version__, "cuda", torch.version.cuda)
a=torch.randn(4,4, device="cuda")
b=torch.randn(4,4, device="cuda")
print((a@b).shape)
PY
Fix (verified)
- Upgrade PyTorch to a 4090-compatible build:
conda install pytorch torchvision torchaudio pytorch-cuda=11.8 -c pytorch -c nvidia
(After this, the minimal matmul prints torch.Size([4,4]).)
- Rebuild CUDA extensions after torch upgrade:
- simple-knn: uninstall + clear
~/.cache/torch_extensions+pip install -e . - If
ImportError: libc10.so not found, export torch libs:
TORCH_LIB=$(python -c "import torch, os; print(os.path.join(os.path.dirname(torch.__file__),'lib'))")
export LD_LIBRARY_PATH="$CONDA_PREFIX/lib:$TORCH_LIB:$LD_LIBRARY_PATH"
- pytorch3d:
pip install pytorch3dmay install an old incompatible version (e.g., 0.3.0).- Uninstall and install a compatible build (source install worked; verify outside the source folder to avoid import shadowing).
Suggestion
Update environment.yaml/README to recommend torch>=2.0 + cu118/cu121 for RTX 40xx (Ada) and note that CUDA extensions must be rebuilt after changing torch.
Sorry, I have not encountered this issue. Could you test your PyTorch environment first? It seems that your PyTorch setup might not be working correctly. For example, torch.mm is a basic operation and should definitely work well in CUDA mode.
Thank you very much for your response. We have now successfully resolved the issue. As mentioned in our previous message, we had already analyzed the root cause. Trusting the YAML configuration you provided, we refrained from modifying any environment settings. Instead, we migrated all operations that were incompatible with torch.mm to the CPU, which initially allowed us to run the instance_train stage successfully—an encouraging outcome at the time. However, fully redirecting all torch.mm operations to the CPU led to a more severe issue: although the training process could proceed, the model failed to converge. During final evaluation, all metrics were zero. After carefully inspecting each step, we found through PCA-based dimensionality reduction visualizations that the instance segmentation component exhibited no convergence behavior. This unexpected outcome was deeply discouraging and almost led us to abandon the effort. Your supportive reply greatly boosted our confidence. We highly value the reliability of your code and the clarity of the README instructions. Upon a complete review, we confirmed that our only modification involved handling the incompatibility between the RTX 4090 GPU and torch==1.12.1, which affected certain computational steps. We then repeated the entire pipeline without any code modifications, resolving the compatibility issues by upgrading to torch 2.0.1 + cu118 and ensuring the consistency of all related packages. Encouragingly, this time we successfully reproduced the results, obtaining performance closely aligned with those reported in your paper. Once again, we thank you for your support. This is an impressive piece of work, and we look forward to seeing more of your future research.
I am happy to hear that! By the way, I have updated the reminder about checking the CUDA version in the README. Thanks for your kind words. :)
Cheers!