tensorflow
oneDNN
custom operations
port.cc
warnings

Warning while using tensorflow tensorflow/core/util/port.cc113 oneDNN custom operations are on

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

Introduction

The message tensorflow/core/util/port.cc:113: oneDNN custom operations are on is an informational log, not an error. It means TensorFlow is using Intel's oneDNN (formerly MKL-DNN) library to accelerate CPU operations like convolutions, matrix multiplications, and batch normalization. This is normal behavior on Intel CPUs and generally improves performance. To suppress the message, set the environment variable TF_ENABLE_ONEDNN_OPTS=0 (disables oneDNN) or adjust TensorFlow's log level with TF_CPP_MIN_LOG_LEVEL=2.

What the Message Means

 
1I tensorflow/core/util/port.cc:113] oneDNN custom operations are on.
2You may see slightly different numerical results due to floating-point round-off
3errors from different computation orders. To turn them off, set the environment
4variable `TF_ENABLE_ONEDNN_OPTS=0`.

This is a LOG(INFO) message — the I prefix means "information." TensorFlow is telling you that:

  1. oneDNN optimized kernels are active for CPU operations
  2. Floating-point results may differ slightly from non-oneDNN execution
  3. You can disable it if exact numerical reproducibility is required

Why oneDNN Is Enabled

Starting with TensorFlow 2.9+, oneDNN optimizations are enabled by default on Intel CPUs. oneDNN accelerates:

  • Convolution operations (Conv2D, Conv3D)
  • Matrix multiplications (MatMul, Dense layers)
  • Batch normalization
  • Pooling operations
  • RNN/LSTM layers
  • Activation functions
python
1import tensorflow as tf
2
3# Check if oneDNN is active
4print(tf.config.list_physical_devices())
5# You'll see CPU device — oneDNN optimizes CPU operations
6
7# The message appears during import or first operation
8model = tf.keras.Sequential([tf.keras.layers.Dense(10)])
9model(tf.random.normal([1, 5]))  # Triggers the log message

Suppressing the Message

Option 1: Set TF_CPP_MIN_LOG_LEVEL (Suppress Logs Only)

This hides the message without disabling oneDNN optimizations:

python
1import os
2os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'  # Set BEFORE importing tensorflow
3
4import tensorflow as tf
5# No info messages shown
bash
# Or set via shell environment
export TF_CPP_MIN_LOG_LEVEL=2
python my_script.py

Log level values:

ValueEffect
0Show all messages (default)
1Filter out INFO messages
2Filter out INFO and WARNING
3Filter out INFO, WARNING, and ERROR

Option 2: Disable oneDNN (TF_ENABLE_ONEDNN_OPTS=0)

This disables the optimizations entirely:

python
1import os
2os.environ['TF_ENABLE_ONEDNN_OPTS'] = '0'  # Set BEFORE importing tensorflow
3
4import tensorflow as tf
5# oneDNN is disabled — uses default TensorFlow kernels
bash
export TF_ENABLE_ONEDNN_OPTS=0
python my_script.py

Only disable oneDNN if you need exact numerical reproducibility between runs or between CPU and GPU results.

Option 3: Python Logging Level

python
1import os
2os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
3
4import tensorflow as tf
5import logging
6tf.get_logger().setLevel(logging.ERROR)
7
8# Both C++ and Python TensorFlow logs are suppressed

Numerical Differences from oneDNN

oneDNN uses optimized computation orders (e.g., fused multiply-add, different reduction trees) that change floating-point rounding:

python
1import os
2import numpy as np
3import tensorflow as tf
4
5# With oneDNN (default)
6os.environ['TF_ENABLE_ONEDNN_OPTS'] = '1'
7a = tf.random.normal([100, 100], seed=42)
8b = tf.random.normal([100, 100], seed=43)
9result_on = tf.matmul(a, b).numpy()
10
11# Without oneDNN
12os.environ['TF_ENABLE_ONEDNN_OPTS'] = '0'
13result_off = tf.matmul(a, b).numpy()
14
15# Differences are tiny (around 1e-6 to 1e-7)
16diff = np.abs(result_on - result_off).max()
17print(f"Max difference: {diff}")  # ~1e-6

These differences are within normal floating-point precision and do not affect model quality.

Performance Impact

oneDNN typically provides 1.5x-3x speedup for CPU inference:

python
1import tensorflow as tf
2import time
3import os
4
5model = tf.keras.Sequential([
6    tf.keras.layers.Dense(512, activation='relu', input_shape=(784,)),
7    tf.keras.layers.Dense(256, activation='relu'),
8    tf.keras.layers.Dense(10, activation='softmax')
9])
10
11data = tf.random.normal([1000, 784])
12
13# Warm up
14model.predict(data, verbose=0)
15
16# Benchmark
17start = time.time()
18for _ in range(100):
19    model.predict(data, verbose=0)
20elapsed = time.time() - start
21print(f"Time: {elapsed:.2f}s")
22
23# With oneDNN: ~X seconds
24# Without oneDNN: ~1.5-3X seconds (slower)

Threading Configuration

oneDNN threading can be tuned for better performance:

python
1import os
2
3# Set number of threads for oneDNN operations
4os.environ['OMP_NUM_THREADS'] = '4'
5os.environ['MKL_NUM_THREADS'] = '4'
6
7# TensorFlow inter/intra op parallelism
8import tensorflow as tf
9tf.config.threading.set_inter_op_parallelism_threads(2)
10tf.config.threading.set_intra_op_parallelism_threads(4)

Dockerfile Example

dockerfile
1FROM python:3.10-slim
2
3# Suppress TensorFlow info messages
4ENV TF_CPP_MIN_LOG_LEVEL=2
5
6# Optional: tune threading
7ENV OMP_NUM_THREADS=4
8ENV MKL_NUM_THREADS=4
9
10RUN pip install tensorflow
11COPY app.py .
12CMD ["python", "app.py"]

Common Pitfalls

  • Setting environment variables after importing TensorFlow: os.environ['TF_CPP_MIN_LOG_LEVEL'] and os.environ['TF_ENABLE_ONEDNN_OPTS'] must be set before import tensorflow. Setting them after the import has no effect because TensorFlow reads them during initialization.
  • Disabling oneDNN for performance-critical CPU workloads: Turning off oneDNN with TF_ENABLE_ONEDNN_OPTS=0 reduces CPU inference speed by 1.5-3x. Only disable it if numerical reproducibility is required, not just to suppress the log message.
  • Confusing the info message with an error: The I prefix means INFO. This is not a warning or error — it is purely informational. Setting TF_CPP_MIN_LOG_LEVEL=1 suppresses it without any side effects.
  • Expecting GPU operations to be affected: oneDNN only optimizes CPU operations. GPU operations use cuDNN instead. The message appears even when a GPU is available because TensorFlow initializes CPU kernels during startup.
  • Assuming numerical differences indicate a bug: The ~1e-6 differences from oneDNN are normal floating-point behavior. Model accuracy, loss values, and predictions are not meaningfully affected. Do not disable oneDNN to "fix" these differences.

Summary

  • The oneDNN custom operations are on message is informational, not an error
  • oneDNN accelerates CPU operations (convolution, matmul, batch norm) by 1.5-3x
  • Suppress with TF_CPP_MIN_LOG_LEVEL=2 (hides message, keeps optimization)
  • Disable with TF_ENABLE_ONEDNN_OPTS=0 only if exact numerical reproducibility is needed
  • Set environment variables before import tensorflow for them to take effect

Course illustration
Course illustration

All Rights Reserved.