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

- **ID:** `tensorflow/tf-data-cpu-affinity-error`
- **领域:** tensorflow
- **类别:** runtime_error
- **错误码:** `CP`
- **验证级别:** ai_generated
- **修复率:** 90%

## 根因

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

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| tensorflow 2.10 | active | — | — |
| tensorflow 2.11 | active | — | — |
| tensorflow 2.12 | active | — | — |

## 解决方案

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
   ```

## 无效尝试

- **** — The error is a hard InvalidArgumentError, not a warning; logging suppression does not prevent the crash. (95% 失败率)
- **** — The issue is at the OS/kernel level, not a library bug; reinstallation does not change platform support. (90% 失败率)
