Skip to content

Conversation

@pitangainnovare
Copy link
Contributor

Controle de suporte a instruções AVX

Descrição

Permite ao usuário, via build, desativar o suporte a AVX (Advanced Vector Extensions), que é um conjunto de instruções de CPU que acelera cálculos matemáticos pesados, muito usados em processamento vetorial e aprendizado de máquina. No Dockerfile, por padrão, essas instruções estão ativadas, o que pode causar core dumped em CPUs antigas (como algumas do Kubernetes). Neste projeto, essa instrução é importante para a biblioteca llama-cpp-python.

Como isso afeta o llama-cpp-python

O llama-cpp-python usa código otimizado que, por padrão, ativa AVX/AVX2 para acelerar a inferência do modelo. Se a CPU não suporta AVX, tentar rodar esse código gera erro Illegal instruction. Desabilitar AVX no build faz o código usar versões menos otimizadas, mas compatíveis com CPUs mais antigas.

Configuração

No ambiente de build, crie a variável de ambiente DISABLE_AVX=True, para suportar CPUs mais antigas.

Como identificar se a CPU possui suporte a instruções AVX

lscpu | grep avx
Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf tsc_known_freq pni pclmulqdq dtes64 monitor ds_cpl vmx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb ssbd ibrs ibpb stibp ibrs_enhanced tpr_shadow flexpriority ept vpid ept_ad fsgsbase tsc_adjust sgx bmi1 avx2 smep bmi2 erms invpcid avx512f avx512dq rdseed adx smap avx512ifma clflushopt intel_pt avx512cd sha_ni avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves split_lock_detect dtherm ida arat pln pts hwp hwp_notify hwp_act_window hwp_epp hwp_pkg_req vnmi avx512vbmi umip pku ospke avx512_vbmi2 gfni vaes vpclmulqdq avx512_vnni avx512_bitalg avx512_vpopcntdq rdpid sgx_lc fsrm md_clear flush_l1d arch_capabilities

Caso o grep acima não retorne informações, não há suporte ao AVX.

Resumo

  • Com AVX ativado: mais rápido, só roda em CPUs modernas.
  • Com AVX desativado: mais lento, roda em qualquer CPU.

@pitangainnovare pitangainnovare requested a review from Copilot July 31, 2025 18:35
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds the ability to disable AVX (Advanced Vector Extensions) instructions during the build process to support older CPUs that may not have AVX support, particularly for Kubernetes nodes where AVX-enabled binaries can cause core dumps.

  • Updated llama-cpp-python from version 0.3.1 to 0.3.14
  • Added conditional AVX support configuration in both production and local Docker environments
  • Implemented separate installation of llama-cpp-python with appropriate CMAKE flags based on DISABLE_AVX build argument

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
requirements/base.txt Updates llama-cpp-python version from 0.3.1 to 0.3.14
compose/production/django/Dockerfile Adds conditional AVX support with DISABLE_AVX=true default and separate llama-cpp-python installation
compose/local/django/Dockerfile Adds conditional AVX support with DISABLE_AVX=false default and optimized build configuration

pitangainnovare and others added 2 commits July 31, 2025 15:36
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@pitangainnovare pitangainnovare merged commit fd75a6a into scieloorg:main Jul 31, 2025
3 checks passed
@pitangainnovare pitangainnovare deleted the feat/avx-disable-option branch July 31, 2025 18:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant