{
  "id": "tensorflow/gpu-visible-devices-invalid-id",
  "signature": "InternalError: CUDA_ERROR_INVALID_DEVICE: invalid device ordinal",
  "signature_zh": "内部错误：CUDA_ERROR_INVALID_DEVICE：无效的设备序号",
  "regex": "CUDA_ERROR_INVALID_DEVICE: invalid device ordinal",
  "domain": "tensorflow",
  "category": "config_error",
  "subcategory": null,
  "root_cause": "CUDA_VISIBLE_DEVICES environment variable references a GPU index that does not exist on the system.",
  "root_cause_type": "generic",
  "root_cause_zh": "CUDA_VISIBLE_DEVICES 环境变量引用了系统中不存在的 GPU 索引。",
  "versions": [
    {
      "version": "tensorflow 2.12",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "tensorflow 2.13",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "tensorflow 2.14",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "cuda 11.8",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "cuda 12.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "Reinstalling CUDA drivers",
      "why_fails": "The issue is not driver installation but environment variable misconfiguration; reinstalling drivers does not fix the ordinal mapping.",
      "fail_rate": 0.95,
      "condition": "",
      "sources": []
    },
    {
      "action": "Setting CUDA_VISIBLE_DEVICES to all GPUs (e.g., '0,1,2,3') blindly",
      "why_fails": "If the system has fewer GPUs than specified, the error persists; the correct approach is to query available devices first.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "List available GPUs with nvidia-smi, then set CUDA_VISIBLE_DEVICES to a valid index. For example: export CUDA_VISIBLE_DEVICES=0 (if only one GPU exists). In Python: import os; os.environ['CUDA_VISIBLE_DEVICES'] = '0'; import tensorflow as tf; print(tf.config.list_physical_devices('GPU'))",
      "success_rate": 0.95,
      "how": "List available GPUs with nvidia-smi, then set CUDA_VISIBLE_DEVICES to a valid index. For example: export CUDA_VISIBLE_DEVICES=0 (if only one GPU exists). In Python: import os; os.environ['CUDA_VISIBLE_DEVICES'] = '0'; import tensorflow as tf; print(tf.config.list_physical_devices('GPU'))",
      "condition": "",
      "sources": []
    },
    {
      "action": "Remove CUDA_VISIBLE_DEVICES entirely to let TensorFlow auto-detect all GPUs: unset CUDA_VISIBLE_DEVICES",
      "success_rate": 0.85,
      "how": "Remove CUDA_VISIBLE_DEVICES entirely to let TensorFlow auto-detect all GPUs: unset CUDA_VISIBLE_DEVICES",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "List available GPUs with nvidia-smi, then set CUDA_VISIBLE_DEVICES to a valid index. For example: export CUDA_VISIBLE_DEVICES=0 (if only one GPU exists). In Python: import os; os.environ['CUDA_VISIBLE_DEVICES'] = '0'; import tensorflow as tf; print(tf.config.list_physical_devices('GPU'))",
    "Remove CUDA_VISIBLE_DEVICES entirely to let TensorFlow auto-detect all GPUs: unset CUDA_VISIBLE_DEVICES"
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://www.tensorflow.org/guide/gpu#limiting_gpu_memory_growth",
  "official_doc_section": null,
  "error_code": "GID",
  "verification_tier": "ai_generated",
  "confidence": 0.85,
  "fix_success_rate": 0.9,
  "resolvable": "true",
  "first_seen": "2023-05-10",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}