# 转换器错误：Flex 委托未启用；某些操作不受 TFLite 运行时支持

- **ID:** `tensorflow/tflite-flex-op-delegate`
- **领域:** tensorflow
- **类别:** build_error
- **错误码:** `TFD`
- **验证级别:** ai_generated
- **修复率:** 85%

## 根因

模型使用了 TFLite 原生不支持的 TensorFlow 操作，且转换器未配置为回退到 Flex 操作。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| tensorflow 2.13 | active | — | — |
| tensorflow 2.14 | active | — | — |
| tensorflow 2.15 | active | — | — |
| tflite 2.13 | active | — | — |
| tflite 2.14 | active | — | — |

## 解决方案

1. ```
   Enable Flex ops in the converter: converter = tf.lite.TFLiteConverter.from_saved_model('model_dir'); converter.target_spec.supported_ops = [tf.lite.OpsSet.TFLITE_BUILTINS, tf.lite.OpsSet.SELECT_TF_OPS]; tflite_model = converter.convert()
   ```
2. ```
   Replace unsupported ops with TFLite-compatible alternatives (e.g., replace tf.nn.softmax_cross_entropy_with_logits with tf.keras.losses.CategoricalCrossentropy). Then retry conversion without Flex.
   ```

## 无效尝试

- **Adding allow_custom_ops=True without enabling Flex** — Custom ops are different from Flex ops; this flag only allows custom ops, not TensorFlow ops via Flex. (80% 失败率)
- **Using tf.lite.TFLiteConverter.from_keras_model instead of from_saved_model** — The converter source does not affect op support; Flex must be explicitly enabled regardless. (95% 失败率)
