Skip to content

Segmentation fault on CPU-only VM when running TensorFlow #104830

Closed

Description

@moyudadi

Issue type

Bug

Have you reproduced the bug with TensorFlow Nightly?

Yes

Source

source

TensorFlow version

tensorflow==2.20.0

Custom code

Yes

OS platform and distribution

Kali Linux (kali-rolling) Linux kernel: 6.11.2-amd64

Mobile device

Not applicable (running on VMware VM)

Python version

3.10

Bazel version

No response

GCC/compiler version

No response

CUDA/cuDNN version

No response

GPU model and memory

No response

Current behavior?

Running TensorFlow on a CPU-only VMware virtual machine produces a native segmentation fault.
Before the crash, TensorFlow attempts to initialize CUDA (cuInit), which fails with error 303:

E cuda_platform.cc:50] failed call to cuInit: INTERNAL: CUDA error: UNKNOWN ERROR (303)

Immediately after this message, Python terminates with:

zsh: segmentation fault python q1.py

No Python stack trace is shown. This is a native C++ runtime crash.
The same behavior occurs with both stable TensorFlow (2.20.0) and tf-nightly.

Standalone code to reproduce the issue

import tensorflow as tf
seq_len_max = tf.constant(1, dtype=tf.int64)
# shapes: time=1, batch=1, input=1, cell=1
x = tf.constant([[[1.0]]], dtype=tf.float32)        # [time, batch, input]
cs_prev = tf.constant([[1.0]], dtype=tf.float32)    # [batch, cell]
h_prev = tf.constant([[1.0]], dtype=tf.float32)    # [batch, cell]
w = tf.constant([[1.0]], dtype=tf.float32)        # rank-2 weight placeholder
wci = tf.constant([1.0], dtype=tf.float32)         # [cell]
wcf = tf.constant([1.0], dtype=tf.float32)
wco = tf.constant([1.0], dtype=tf.float32)
b = tf.constant([1.0], dtype=tf.float32)
# gate/state tensors: [time, batch, cell]
i = tf.constant([[[1.0]]], dtype=tf.float32)
cs = tf.constant([[[1.0]]], dtype=tf.float32)
f = tf.constant([[[1.0]]], dtype=tf.float32)
o = tf.constant([[[1.0]]], dtype=tf.float32)
ci = tf.constant([[[1.0]]], dtype=tf.float32)
co = tf.constant([[[1.0]]], dtype=tf.float32)
h = tf.constant([[[1.0]]], dtype=tf.float32)
cs_grad = tf.constant([[[1.0]]], dtype=tf.float32)
h_grad = tf.constant([[[1.0]]], dtype=tf.float32)

result = tf.raw_ops.BlockLSTMGradV2(seq_len_max=seq_len_max, x=x, cs_prev=cs_prev, h_prev=h_prev, w=w, wci=wci, wcf=wcf, wco=wco, b=b, i=i, cs=cs, f=f, o=o, ci=ci, co=co, h=h, cs_grad=cs_grad, h_grad=h_grad, use_peephole=True)
print(result)

Relevant log output

Same behavior reproduced with tf-nightly before crashing:
E cuda_platform.cc:50] failed call to cuInit: INTERNAL: CUDA error: UNKNOWN ERROR (303)
zsh: segmentation fault  python q1.py

Activity

  1. Kayyuri commented on Jul 20, 2026

    @Kayyuri

    Hi @moyudadi,
    Thank you so much for filing this issue! We truly appreciate your support. At the moment, this request is not prioritized and mark it for community contributions. If you would like to contribute on a fix, please feel free to fork the repository and submit a pull request in accordance with the TensorFlow CONTRIBUTION GUIDELINES and link this issue in your PR to ensure the maintainers can easily review and collaborate.
    To avoid duplicate work, please leave a comment here if you decide to take it on!

    Thank you again for your interest and we look forward to seeing your contributions!

  2. added
    stat:contribution welcome
    on Jul 20, 2026
  3. hunterkritik-byte commented on Aug 11, 2026

    @hunterkritik-byte
    Contributor

    Root Cause Analysis

    When invoking tf.raw_ops.BlockLSTMGrad / tf.raw_ops.BlockLSTMGradV2 with mismatched tensor dimensions (such as passing a weight matrix w of shape [1, 1] when input_size=1 and cell_size=1), BlockLSTMGradOp::Compute does not enforce strict shape compatibility checks on the weight tensor w and gate inputs relative to input_size and cell_size.

    Technical Details

    1. Expected Tensor Dimensions:

      • For an input $x$ of shape [seq_len, batch_size, input_size] and hidden cell state of size cell_size, the concatenated transformation weight matrix $W$ is required to have shape [input_size + cell_size, 4 * cell_size] to accommodate the 4 LSTM gates ($i, f, o, ci$).
      • In the provided reproduction script, input_size = 1 and cell_size = 1, which strictly requires $W$ to be of shape [2, 4]. However, $W$ was passed as [1, 1].
    2. Memory Safety Violation:

      • Because BlockLSTMGradOp::Compute lacks an explicit OP_REQUIRES check validating that w.dim_size(0) == input_size + cell_size and w.dim_size(1) == 4 * cell_size, execution proceeds to the kernel functor.
      • When Eigen matrix operations (TensorAdd / tensor contractions) execute inside the kernel worker threads, Eigen attempts to access out-of-bounds memory beyond the allocated buffer for w.
      • This results in an immediate SIGSEGV segmentation fault inside Eigen::ThreadPoolDevice::parallelFor rather than raising a clean InvalidArgumentError.

    Proposed Fix

    Add explicit input tensor shape validation checks in BlockLSTMGradOp::Compute prior to kernel execution:

    • Validate w.dim_size(0) == input_size + cell_size
    • Validate w.dim_size(1) == 4 * cell_size
    • Validate gate/bias shapes against cell_size and batch_size
  4. added
    awaiting PR merge
    and removed
    stat:contribution welcome
    on Aug 11, 2026
  5. google-ml-butler commented on Aug 24, 2026

    @google-ml-butler

    Are you satisfied with the resolution of your issue?
    Yes
    No

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions