Skip to content

[Bug] Pytorch CUDA 13 'torch._C._CudaDeviceProperties' object has no attribute 'total_mem' #59

Description

@alroman2

Using pytorch for cuda 13 causes attribute error for methods that check the device property memory during train_model.py.

python src/bot_mmorpg/scripts/train_model.py --data data/raw --model efficientnet_lstm
[Warning] Could not import models_pytorch: attempted relative import with no known parent package
Traceback (most recent call last):
  File "G:\Git\bot\BOT-MMORPG-AI\src\bot_mmorpg\scripts\train_model.py", line 717, in <module>
    sys.exit(main())
             ^^^^^^
  File "G:\Git\bot\BOT-MMORPG-AI\src\bot_mmorpg\scripts\train_model.py", line 589, in main
    total_mem_gb = torch.cuda.get_device_properties(0).total_mem / 1e9
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'torch._C._CudaDeviceProperties' object has no attribute 'total_mem'. Did you mean: 'total_memory'?

Impact:

  1. Training completely fails due to torch device property call differring for cuda 13 pytorch.

Steps to reproduce:

  1. Install pytorch from --index-url https://download.pytorch.org/whl/cu130
  2. Attempt to run python src/bot_mmorpg/scripts/train_model.py

Proposed Fixes:

  1. consider get_device_properties as a nullable operation and safely unwrap the result. If we are logging provide an error string and log the issue.
  2. If we require the total memory such as when auto batch size is being calculated -> provide a safe default value if we unwrap a null value
def _log_gpu_memory(prefix: str = "") -> None:
    """Print current GPU memory usage (no-op on CPU)."""
    if not PYTORCH_AVAILABLE or not torch.cuda.is_available():
        return
    alloc = torch.cuda.memory_allocated() / 1e9
    reserved = torch.cuda.memory_reserved() / 1e9
    total = torch.cuda.get_device_properties(0).total_mem / 1e9 <- unsafe a will crash program on cuda 13
    print(
        f"  [GPU] {prefix}Allocated: {alloc:.2f}GB | Reserved: {reserved:.2f}GB | Total: {total:.2f}GB"
    )
  # Auto-detect safe batch-size for GPU VRAM (fixes #27 — CUDA OOM on 8GB cards)
    batch_size = args.batch_size
    if device.type == "cuda" and not args.cpu:
        total_mem_gb = torch.cuda.get_device_properties(0).total_mem / 1e9  <- unsafe a will crash program on cuda 13
        if total_mem_gb <= 6 and batch_size > 4:
            old_bs = batch_size
            batch_size = 4
            use_amp = True
            use_grad_ckpt = True
            print(
                f"[Auto] GPU has {total_mem_gb:.1f}GB VRAM — "
                f"reducing batch_size {old_bs} -> {batch_size}, "
                f"enabling AMP (fp16) and gradient checkpointing"
            )

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions