CP tensorflow runtime_error ai_generated true

InvalidArgumentError: 此平台不支持 CPU 亲和性 [Op:ModelDataset]

InvalidArgumentError: CPU affinity is not supported on this platform [Op:ModelDataset]

ID: tensorflow/tf-data-cpu-affinity-error

其他格式: JSON · Markdown 中文 · English
90%修复率
85%置信度
1证据数
2023-03-15首次发现

版本兼容性

版本状态引入弃用备注
tensorflow 2.10 active
tensorflow 2.11 active
tensorflow 2.12 active

根因分析

TF Data 自动调优启用了 CPU 亲和性,但当前平台(如 macOS 或特定容器环境)不支持 sched_setaffinity。

English

TF Data autotuning with CPU affinity is enabled on a platform that does not support sched_setaffinity (e.g., macOS or certain container environments).

generic

官方文档

https://www.tensorflow.org/api_docs/python/tf/data/experimental/AutotuneOptions

解决方案

  1. 在构建数据集管道之前,通过 tf.data.experimental.AutotuneOptions 设置 autotune_cpu_affinity=False 来禁用自动调优 CPU 亲和性。
  2. 在支持 sched_setaffinity 的 Linux 容器(Docker)中运行脚本,例如 docker run --rm -it tensorflow/tensorflow:latest python script.py

无效尝试

常见但无效的做法:

  1. 95% 失败

    The error is a hard InvalidArgumentError, not a warning; logging suppression does not prevent the crash.

  2. 90% 失败

    The issue is at the OS/kernel level, not a library bug; reinstallation does not change platform support.