Docker build fails with "Illegal instruction" on CPUs without AVX2 support

#1
by florinbadita - opened

Problem

The Docker build for ten-agent-demo fails during the agent build step with an "Illegal instruction" error when running on systems without AVX2 CPU support.


Environment

  • OS: Linux (x86_64)
  • Docker Version: [your version]
  • Base Image: ghcr.io/ten-framework/ten_agent_build:0.6.1-cuda
  • Branch: feature/ttd
  • CPU Flags: fpu de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx lm constant_tsc nopl xtopology cpuid tsc_known_freq pni ssse3 cx16 sse4_1 sse4_2 x2apic popcnt aes hypervisor lahf_lm cpuid_fault pti

Missing: AVX, AVX2 (common in VM environments)


Steps to Reproduce

1. Use the following Dockerfile:

FROM ghcr.io/ten-framework/ten_agent_build:0.6.1-cuda

RUN pip install "huggingface_hub[cli]" hf_transfer
RUN pip install --no-cache-dir --upgrade pip \
 && pip install --no-cache-dir --pre git+https://github.com/huggingface/transformers.git@main \
 && pip install --no-cache-dir --pre vllm

ENV NVM_DIR=/usr/local/nvm
RUN mkdir -p $NVM_DIR
ENV BASH_ENV=/usr/local/nvm/.nvm_bash_env
RUN touch "${BASH_ENV}"
RUN echo '. "${BASH_ENV}"' >> ~/.bashrc
RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.2/install.sh | PROFILE="${BASH_ENV}" bash
RUN . $NVM_DIR/nvm.sh && nvm install node

RUN git clone -b feature/ttd https://github.com/TEN-framework/ten_framework.git /ten_framework
RUN ln -sf /ten_framework/ai_agents /app
RUN cd /app && task use AGENT=agents/examples/huggingface && cd agents && ./scripts/package.sh

2. Build the image:

docker build --platform linux/amd64 -t ten-agent-demo .

Error Output

> [11/19] RUN cd /app && task use AGENT=agents/examples/huggingface && cd agents && ./scripts/package.sh:
0.117 task: [build-agent] ./scripts/install_deps_and_build.sh linux x64 && mv bin/main bin/worker
0.446 /app/agents/scripts/install_deps_and_build.sh: line 100:   304 Illegal instruction     (core dumped) /tmp/test
0.446 FATAL: unsupported platform.
0.446        Please UNCHECK the 'Use Rosetta for x86_64/amd64 emulation on Apple Silicon' Docker Desktop setting if you're running on mac.
0.447 task: Failed to run task "use": exit status 1

Root Cause

The build script /app/agents/scripts/install_deps_and_build.sh (lines 134–136) performs an AVX2 CPU feature check:

echo -e "#include <stdio.h>\n#include <immintrin.h>\nint main() { __m256 a = _mm256_setzero_ps(); return 0; }" > /tmp/test.c
if gcc -mavx2 /tmp/test.c -o /tmp/test && ! /tmp/test; then
  echo "FATAL: unsupported platform."

The test binary is compiled with -mavx2 and crashes with Illegal instruction on CPUs without AVX2 support.


Temporary Workaround

Patch the Dockerfile to skip the check:

RUN sed -i '135s|if gcc -mavx2 /tmp/test.c -o /tmp/test && ! /tmp/test; then|if false; then|' \
    /app/agents/scripts/install_deps_and_build.sh

⚠️ Note: This workaround allows the build to complete but may cause runtime issues.


Suggested Solutions

  1. Provide non-AVX2 build option: Add an environment variable to disable AVX2 optimizations for compatibility mode.
  2. Improve platform check: Make the check more graceful β€” warn instead of fail, or provide -march=native vs -march=x86-64 build options.
  3. Documentation: Clearly state the minimum CPU requirements (AVX2 support) in the README.
  4. Alternative base images: Provide base images compiled for different CPU feature levels.

Questions

  • Is AVX2 a hard requirement for TEN-Agent to function?
  • Can the native components be compiled without AVX2 optimizations?
  • Are there plans to support older CPU architectures or VM environments without AVX2?

Sign up or log in to comment