### Install k6 on Arch and Debian/Ubuntu Source: https://github.com/aiptimizer/turboocr/blob/main/tests/TESTING_GUIDE.md Installation commands for k6 load testing tool on Arch (pacman) and Debian/Ubuntu (apt with GPG key setup). ```bash # Arch sudo pacman -S k6 # Debian/Ubuntu sudo gpg -k sudo gpg --no-default-keyring --keyring /usr/share/keyrings/k6-archive-keyring.gpg \ --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys C5AD17C747E3415A3642D57D77C6C491D6AC1D68 echo "deb [signed-by=/usr/share/keyrings/k6-archive-keyring.gpg] https://dl.k6.io/deb stable main" \ | sudo tee /etc/apt/sources.list.d/k6.list sudo apt update && sudo apt install k6 ``` -------------------------------- ### Install Google Benchmark Source: https://github.com/aiptimizer/turboocr/blob/main/tests/TESTING_GUIDE.md Installs the Google Benchmark library on Debian/Ubuntu or Arch Linux. Alternatively, build from source. ```bash sudo apt install libbenchmark-dev # Debian/Ubuntu sudo pacman -S benchmark # Arch # or build from source: https://github.com/google/benchmark ``` -------------------------------- ### Install IWYU Source: https://github.com/aiptimizer/turboocr/blob/main/tests/TESTING_GUIDE.md Installation commands for Include What You Use on Debian/Ubuntu and Arch Linux. ```bash sudo apt install iwyu # Debian/Ubuntu sudo pacman -S include-what-you-use # Arch ``` -------------------------------- ### Install ghz for gRPC load testing Source: https://github.com/aiptimizer/turboocr/blob/main/tests/TESTING_GUIDE.md Installation commands for ghz using go install or downloading a binary from the releases page. ```bash go install github.com/bojand/ghz/cmd/ghz@latest # or download binary from https://github.com/bojand/ghz/releases ``` -------------------------------- ### Install Valgrind Source: https://github.com/aiptimizer/turboocr/blob/main/tests/TESTING_GUIDE.md Install Valgrind on Debian/Ubuntu or Arch Linux. ```bash sudo apt install valgrind # Debian/Ubuntu sudo pacman -S valgrind # Arch ``` -------------------------------- ### Install rules for server binary and data Source: https://github.com/aiptimizer/turboocr/blob/main/CMakeLists.txt Installs the server executable to bin and copies models and scripts directories. The models directory is optional; scripts preserve source permissions. Works with `cmake --install build --prefix /usr/local`. ```cmake if(USE_CPU_ONLY) install(TARGETS turboocr-cpu-server RUNTIME DESTINATION bin) else() install(TARGETS turboocr-server RUNTIME DESTINATION bin) endif() install(DIRECTORY models/ DESTINATION share/turbo-ocr/models OPTIONAL) install(DIRECTORY scripts/ DESTINATION share/turbo-ocr/scripts USE_SOURCE_PERMISSIONS) ``` -------------------------------- ### Run Qwen3-VL-2B benchmark Source: https://github.com/aiptimizer/turboocr/blob/main/tests/benchmark/comparison/README.md Starts a vLLM server for Qwen3-VL-2B-Instruct and runs the async VLM benchmark. The server must be started in a separate terminal. ```bash vllm serve Qwen/Qwen3-VL-2B-Instruct --port 8077 --host 0.0.0.0 \ --max-model-len 8192 --max-num-seqs 16 --gpu-memory-utilization 0.75 ``` ```bash .venv/bin/python bench_vlm_async.py \ Qwen/Qwen3-VL-2B-Instruct "Qwen3-VL-2B" 8077 "OCR:" ``` -------------------------------- ### Install cppcheck Source: https://github.com/aiptimizer/turboocr/blob/main/tests/TESTING_GUIDE.md Installation commands for cppcheck on Debian/Ubuntu and Arch Linux. ```bash sudo apt install cppcheck # Debian/Ubuntu sudo pacman -S cppcheck # Arch ``` -------------------------------- ### Run all test suites Source: https://github.com/aiptimizer/turboocr/blob/main/tests/TESTING_GUIDE.md Installs test dependencies and runs the full test suite or a specific suite using the run_all.py script. ```bash pip install -r tests/requirements.txt python tests/run_all.py # all suites python tests/run_all.py --suite unit # just unit python tests/run_all.py --suite benchmark # just benchmarks ``` -------------------------------- ### AFL++ setup and run Source: https://github.com/aiptimizer/turboocr/blob/main/tests/TESTING_GUIDE.md Install AFL++, compile the libFuzzer-compatible harness with afl-clang-fast++, and run afl-fuzz with a seed input. The seed file contains a valid base64 string. ```bash # Install sudo apt install aflplusplus # or build from source # Compile (harnesses are compatible with libFuzzer) afl-clang-fast++ -g -O1 -fsanitize=address \ -I include -I third_party \ -std=c++20 \ tests/fuzz/fuzz_base64.cpp \ -o fuzz_base64_afl # Run mkdir -p afl_input afl_output echo "SGVsbG8=" > afl_input/seed.txt # valid base64 seed afl-fuzz -i afl_input -o afl_output -- ./fuzz_base64_afl ``` -------------------------------- ### Install Locust Source: https://github.com/aiptimizer/turboocr/blob/main/tests/TESTING_GUIDE.md Command to install the Locust load testing library via pip. ```bash pip install locust ``` -------------------------------- ### Build and run C++ benchmark manually Source: https://github.com/aiptimizer/turboocr/blob/main/tests/TESTING_GUIDE.md Compiles bench_base64.cpp with g++ and runs it, outputting JSON results to bench_base64.json. Requires Google Benchmark installed. ```bash g++ -std=c++20 -O3 -march=native \ -I include -I third_party \ tests/cpp_bench/bench_base64.cpp \ -lbenchmark -lpthread \ -o bench_base64 ./bench_base64 --benchmark_format=json --benchmark_out=bench_base64.json ``` -------------------------------- ### Run all Python test suites Source: https://github.com/aiptimizer/turboocr/blob/main/docs/dev/testing.md Runs every suite including opt-in ones like cpp, stress, and benchmark. ```bash python tests/run_all.py --suite all ``` -------------------------------- ### Sample Prometheus metrics output Source: https://github.com/aiptimizer/turboocr/blob/main/docs/api/monitoring.md Example output from GET /metrics showing counters, histograms, and gauges. Note that GPU VRAM gauges appear only in GPU builds. ```text # HELP turbo_ocr_requests_total Total HTTP requests by route and status. # TYPE turbo_ocr_requests_total counter turbo_ocr_requests_total{route="/ocr/raw",status="2xx"} 1042 turbo_ocr_requests_total{route="/ocr/raw",status="4xx"} 3 turbo_ocr_requests_total{route="/ocr/raw",status="5xx"} 0 # HELP turbo_ocr_request_duration_seconds Request latency histogram. # TYPE turbo_ocr_request_duration_seconds histogram turbo_ocr_request_duration_seconds_bucket{route="/ocr/raw",le="0.025"} 980 turbo_ocr_request_duration_seconds_bucket{route="/ocr/raw",le="+Inf"} 1042 turbo_ocr_request_duration_seconds_sum{route="/ocr/raw"} 21.480000 turbo_ocr_request_duration_seconds_count{route="/ocr/raw"} 1042 # HELP turbo_ocr_pipeline_pool_size Number of pipeline slots. # TYPE turbo_ocr_pipeline_pool_size gauge turbo_ocr_pipeline_pool_size 5 # HELP turbo_ocr_pool_exhaustions_total Times pipeline pool was full (503). # TYPE turbo_ocr_pool_exhaustions_total counter turbo_ocr_pool_exhaustions_total 0 # HELP turbo_ocr_gpu_vram_used_bytes GPU memory currently in use. # TYPE turbo_ocr_gpu_vram_used_bytes gauge turbo_ocr_gpu_vram_used_bytes 9052815360 ``` -------------------------------- ### Build and Run Benchmark Source: https://github.com/aiptimizer/turboocr/blob/main/docs/benchmarks/latency.md Commands to build the project, start the server, and run latency sweeps. The single sweep takes about 78 seconds, while the autonomous loop runs for 3 hours. ```bash # Build (or use the cached engines) cmake -S . -B build -DCMAKE_BUILD_TYPE=Release cmake --build build -j # Start the server LD_LIBRARY_PATH="$HOME/TensorRT-10.15.1.29/lib:$LD_LIBRARY_PATH" \ ./build/turboocr-server --http-port 8000 --log-level warn & # Single sweep (~78 s wall) timeout 120 bash scripts/bench_cua_loop.sh # 3-hour autonomous loop (8–10 sweeps) timeout 11000 bash scripts/bench_cua_loop.sh --loop --window 10800 ``` -------------------------------- ### Start TurboOCR with Optional Stages Source: https://github.com/aiptimizer/turboocr/blob/main/README.md Shows how to enable table and formula backends via environment variables, and how to select a different OCR model. Layout is enabled by default; each extra stage runs only when requested. ```bash # text + layout (default) docker run --gpus all -p 8000:8000 -p 50051:50051 \ -v trt-cache:/home/ocr/.cache/turbo-ocr ghcr.io/aiptimizer/turboocr:latest # + tables (→ HTML) add -e TABLE_BACKEND=slanext # + formulas (→ LaTeX) add -e FORMULA_BACKEND=ppformulanet_s # + both add -e TABLE_BACKEND=slanext -e FORMULA_BACKEND=ppformulanet_s # bigger / other language add -e OCR_MODEL=medium (tiny | small | medium | arabic | eslav | korean | thai | greek) ``` -------------------------------- ### Build and run CPU-only Valgrind Source: https://github.com/aiptimizer/turboocr/blob/main/tests/TESTING_GUIDE.md Build a CPU-only version for Valgrind testing, then run memcheck on it. ```bash cmake -B build_valgrind -DUSE_CPU_ONLY=ON -DCMAKE_BUILD_TYPE=Debug cmake --build build_valgrind -j$(nproc) valgrind --leak-check=full ./build_valgrind/turboocr-cpu-server ``` -------------------------------- ### Build and install Drogon from source Source: https://github.com/aiptimizer/turboocr/blob/main/docs/build/native.md Configure, build, and install Drogon v1.9.12 with all optional backends disabled. Requires sudo for the final install step. ```bash cmake -B build \ -DBUILD_EXAMPLES=OFF -DBUILD_CTL=OFF -DBUILD_ORM=OFF \ -DBUILD_POSTGRESQL=OFF -DBUILD_MYSQL=OFF -DBUILD_SQLITE=OFF \ -DBUILD_REDIS=OFF -DBUILD_TESTING=OFF cmake --build build -j"$(nproc)" sudo cmake --install build ``` -------------------------------- ### Dockerfile entrypoint and CMD Source: https://github.com/aiptimizer/turboocr/blob/main/docs/build/docker.md Sets the entrypoint script and default command for the container. The entrypoint drops privileges to the ocr user, optionally starts nginx, then execs the CMD. ```dockerfile ENTRYPOINT ["/app/scripts/entrypoint.sh"] CMD ["./build/turboocr-server"] ``` -------------------------------- ### Build with ASan Source: https://github.com/aiptimizer/turboocr/blob/main/tests/TESTING_GUIDE.md Configure and build the project with AddressSanitizer enabled. ASan provides ~2x runtime overhead, much faster than Valgrind. ```bash cmake -B build_asan \ -DENABLE_ASAN=ON \ -DTENSORRT_DIR=/usr/local/tensorrt \ -DCMAKE_BUILD_TYPE=RelWithDebInfo cmake --build build_asan -j$(nproc) ``` -------------------------------- ### Docker Compose configuration for GPU image Source: https://github.com/aiptimizer/turboocr/blob/main/docs/build/docker.md Example docker-compose.yml for the GPU image, using the nvidia runtime and mounting the trt-cache volume. The named volume persists TensorRT engines and language bundles. ```yaml # docker/docker-compose.yml is the canonical example. services: turbo-ocr: image: turbo-ocr runtime: nvidia ports: ["8000:8000", "50051:50051"] volumes: ["trt-cache:/home/ocr/.cache/turbo-ocr"] volumes: trt-cache: ``` -------------------------------- ### Build and run C++ unit tests with Catch2 Source: https://github.com/aiptimizer/turboocr/blob/main/docs/dev/testing.md Builds the turbo_ocr_tests binary and runs the full test suite. The binary is built unconditionally alongside the server. ```bash cmake --build build --target turbo_ocr_tests ./build/turbo_ocr_tests ``` -------------------------------- ### Run a single Python test suite Source: https://github.com/aiptimizer/turboocr/blob/main/docs/dev/testing.md Runs a specific suite by name, e.g., unit or benchmark. ```bash python tests/run_all.py --suite unit python tests/run_all.py --suite benchmark ``` -------------------------------- ### JavaScript HTTP GET request using Fetch API Source: https://github.com/aiptimizer/turboocr/blob/main/tests/fixtures/pdf/multi_column.pdf Shows how to make a GET request using the Fetch API, chaining .then() to parse JSON and log the data. ```javascript fetch('/url/to/resource') .then(response => response.json()) .then(data => console.log(data)); ``` -------------------------------- ### GET /capabilities Source: https://github.com/aiptimizer/turboocr/blob/main/README.md Runtime feature & route discovery. Returns information about available features and routes. ```APIDOC ## [GET] /capabilities ### Description Runtime feature & route discovery. Returns information about available features and routes. ### Method GET ### Endpoint /capabilities ### Response #### Success Response (200) Feature and route information. #### Response Example { "features": ["ocr", "layout"], "routes": ["/ocr/raw", "/ocr"] } ``` -------------------------------- ### GET /health, /health/live, /health/ready Source: https://github.com/aiptimizer/turboocr/blob/main/README.md Liveness / readiness probes. Returns health status for the service. ```APIDOC ## [GET] /health, /health/live, /health/ready ### Description Liveness / readiness probes. Returns health status for the service. ### Method GET ### Endpoint /health, /health/live, /health/ready ### Response #### Success Response (200) Health status. #### Response Example { "status": "ok" } ``` -------------------------------- ### Install pre-commit hooks Source: https://github.com/aiptimizer/turboocr/blob/main/docs/dev/pre_commit.md Run once per clone to install the pre-commit hook that performs static checks on staged files. ```bash bash scripts/install_hooks.sh ``` -------------------------------- ### Install test dependencies Source: https://github.com/aiptimizer/turboocr/blob/main/tests/README.md Install the Python packages required for the test suite. ```bash pip install -r tests/requirements.txt ``` -------------------------------- ### Serve PaddleOCR-VL on vLLM with both model names Source: https://github.com/aiptimizer/turboocr/blob/main/docs/resources_speed_accuracy.md Starts a vLLM server for PaddleOCR-VL on port 8077, exposing both 'PaddleOCR-VL-1.5-0.9B' and 'PaddleOCR-VL' so the C++ hybrid and standalone pipeline can resolve the model. ```bash vllm serve models/vlm/paddleocr_vl_1_5 --port 8077 --trust-remote-code \ --served-model-name PaddleOCR-VL-1.5-0.9B PaddleOCR-VL --gpu-memory-utilization 0.45 ``` -------------------------------- ### List all Catch2 tests Source: https://github.com/aiptimizer/turboocr/blob/main/docs/dev/testing.md Lists all registered tests in the turbo_ocr_tests binary using Catch2's --list-tests flag. ```bash ./build/turbo_ocr_tests --list-tests ``` -------------------------------- ### Build and run CPU-only Catch2 tests Source: https://github.com/aiptimizer/turboocr/blob/main/docs/dev/testing.md Builds the standalone Catch2 test suite without CUDA/TensorRT, suitable for CI runners without a GPU. Commands configure, build, and run the tests. ```bash cmake -S tests/cpp -B tests/cpp/build cmake --build tests/cpp/build -j ./tests/cpp/build/turbo_ocr_tests ``` -------------------------------- ### Run test suite against ASan server Source: https://github.com/aiptimizer/turboocr/blob/main/tests/TESTING_GUIDE.md Execute the integration and unit test suites against the server running under ASan. ```bash python tests/run_all.py --suite integration --suite unit ``` -------------------------------- ### Install system packages with pacman Source: https://github.com/aiptimizer/turboocr/blob/main/docs/build/native.md Installs required system packages for the native build on Arch Linux. Uses --needed and --noconfirm flags. OpenCV 4 and 5 are both supported; the configure log shows which version was found. ```bash sudo pacman -S --needed --noconfirm \ cmake opencv protobuf grpc jsoncpp openssl c-ares nginx curl libjpeg-turbo ``` -------------------------------- ### Recommended Pipeline Stages Source: https://github.com/aiptimizer/turboocr/blob/main/tests/TESTING_GUIDE.md Outlines the five-stage CI/CD pipeline: static analysis, build with sanitizers, functional tests, performance tests, and deep analysis. Each stage lists specific tools and commands to run. ```text Stage 1: Static Analysis (fast, no build required) - cppcheck --project=compile_commands.json - clang-tidy on changed files Stage 2: Build + Sanitizer Checks - Build with ENABLE_ASAN=ON, run unit/integration tests - Build with ENABLE_TSAN=ON, run concurrent integration tests - Build with UBSan, run unit tests Stage 3: Functional Tests (requires running server) - python tests/run_all.py --suite unit --suite integration --suite regression Stage 4: Performance (nightly, not on every PR) - python tests/run_all.py --suite benchmark - k6 load test - C++ micro-benchmarks (compare against baseline) Stage 5: Deep Analysis (weekly) - Valgrind memcheck on CPU build - Compute Sanitizer memcheck/racecheck on GPU build - Fuzz testing (continuous, minimum 1 hour per target) ``` -------------------------------- ### Run default Python test suites Source: https://github.com/aiptimizer/turboocr/blob/main/docs/dev/testing.md Runs the default suites (unit, integration, regression, accuracy) via the master driver. ```bash # unit + integration + regression + accuracy python tests/run_all.py ``` -------------------------------- ### Launch C++ server with routing config Source: https://github.com/aiptimizer/turboocr/blob/main/docs/deployment_vl_separate_gpu.md Starts the turboocr-server with the routing configuration file and TensorRT library path. Requires setting TURBO_ROUTING_CONFIG and LD_LIBRARY_PATH environment variables, plus any usual server flags. ```bash TURBO_ROUTING_CONFIG=/path/to/routing.json \ LD_LIBRARY_PATH=/path/to/TensorRT/lib \ ./build/turboocr-server # + your usual server flags ``` -------------------------------- ### Manual UBSan build Source: https://github.com/aiptimizer/turboocr/blob/main/tests/TESTING_GUIDE.md Build with UBSan flags without modifying CMakeLists.txt. Uses CMAKE_CXX_FLAGS and CMAKE_EXE_LINKER_FLAGS. ```bash cmake -B build_ubsan \ -DTENSORRT_DIR=/usr/local/tensorrt \ -DCMAKE_CXX_FLAGS="-fsanitize=undefined -fno-omit-frame-pointer" \ -DCMAKE_EXE_LINKER_FLAGS="-fsanitize=undefined" \ -DCMAKE_BUILD_TYPE=RelWithDebInfo cmake --build build_ubsan -j$(nproc) ``` -------------------------------- ### Run k6 load test Source: https://github.com/aiptimizer/turboocr/blob/main/tests/TESTING_GUIDE.md Commands to execute the k6 script, optionally outputting results to a JSON file. ```bash k6 run tests/loadtest/k6_ocr.js k6 run --out json=k6_results.json tests/loadtest/k6_ocr.js ``` -------------------------------- ### Run Python benchmark suite Source: https://github.com/aiptimizer/turboocr/blob/main/tests/TESTING_GUIDE.md Runs all Python benchmarks and generates a consolidated report. Requires the benchmark suite to be set up. ```bash python tests/run_all.py --suite benchmark python tests/benchmark/bench_report.py ``` -------------------------------- ### Run turboocr-server with PP-OCRv5 model overrides Source: https://github.com/aiptimizer/turboocr/blob/main/docs/build/legacy-ppocrv5.md Starts the server using the legacy PP-OCRv5 detector/recognizer by overriding the per-stage model paths via DET_ONNX, REC_ONNX, and REC_DICT. Requires the three v5 files (det_v5.onnx, rec_v5.onnx, keys_v5.txt) to be supplied manually; the TensorRT engine cache rebuilds on first start, so clear ~/.cache/turbo-ocr if v6 engines were cached under the default model names. The v5 recognizer dictionary is Latin-only (no CJK), so use this for Latin-only workloads or A/B comparison. ```bash DET_ONNX=models/det_v5.onnx \ REC_ONNX=models/rec_v5.onnx \ REC_DICT=models/keys_v5.txt \ LD_LIBRARY_PATH=/usr/local/tensorrt/lib ./build/turboocr-server ``` -------------------------------- ### Run cppcheck Source: https://github.com/aiptimizer/turboocr/blob/main/tests/TESTING_GUIDE.md Run cppcheck with all checks enabled, C++20 standard, and suppressions, using the compile_commands.json project file. ```bash cppcheck --enable=all \ --std=c++20 \ --suppress=missingIncludeSystem \ --suppress=unusedFunction \ --project=build/compile_commands.json \ --output-file=cppcheck_report.txt \ 2>&1 ``` -------------------------------- ### Run PaddleOCR-VL benchmark Source: https://github.com/aiptimizer/turboocr/blob/main/tests/benchmark/comparison/README.md Starts a vLLM server for PaddleOCR-VL and runs the 2-stage pipeline benchmark (layout detector on local GPU, VLM via vLLM). ```bash vllm serve PaddlePaddle/PaddleOCR-VL --port 8077 --host 0.0.0.0 \ --served-model-name PaddleOCR-VL-1.5-0.9B \ --max-num-seqs 64 --gpu-memory-utilization 0.75 ``` ```bash .venv/bin/python bench_paddleocr_vl_pipeline.py ``` -------------------------------- ### Run Valgrind memcheck Source: https://github.com/aiptimizer/turboocr/blob/main/tests/TESTING_GUIDE.md Run Valgrind memcheck with full leak checking and origin tracking. Logs to valgrind.log. ```bash valgrind --tool=memcheck \ --leak-check=full \ --show-leak-kinds=all \ --track-origins=yes \ --log-file=valgrind.log \ ./build/turboocr-server ``` -------------------------------- ### Sync dependencies with uv Source: https://github.com/aiptimizer/turboocr/blob/main/tests/benchmark/comparison/README.md Installs the shared uv project dependencies, including PyTorch nightly cu130 and vLLM nightly for Blackwell SM120. ```bash uv sync ``` -------------------------------- ### Run Turbo-OCR benchmark Source: https://github.com/aiptimizer/turboocr/blob/main/tests/benchmark/comparison/README.md Runs the Turbo-OCR benchmark script. Requires the Turbo-OCR server to be started on port 8000 first. ```bash .venv/bin/python bench_turbo_ocr.py ``` -------------------------------- ### Build with TSan Source: https://github.com/aiptimizer/turboocr/blob/main/tests/TESTING_GUIDE.md Configure and build the project with ThreadSanitizer enabled via the ENABLE_TSAN CMake option. Use RelWithDebInfo for better debugging. ```bash cmake -B build_tsan \ -DENABLE_TSAN=ON \ -DTENSORRT_DIR=/usr/local/tensorrt \ -DCMAKE_BUILD_TYPE=RelWithDebInfo cmake --build build_tsan -j$(nproc) ``` -------------------------------- ### Run IWYU Source: https://github.com/aiptimizer/turboocr/blob/main/tests/TESTING_GUIDE.md Run IWYU tool with a mappings file to reduce false positives for CUDA, TensorRT, and OpenCV headers. ```bash iwyu_tool.py -p build -- -Xiwyu --mapping_file=iwyu_mappings.imp 2>&1 | tee iwyu_report.txt ``` -------------------------------- ### Run UBSan server Source: https://github.com/aiptimizer/turboocr/blob/main/tests/TESTING_GUIDE.md Run the server with UBSan options to log reports to ubsan.log. print_stacktrace and halt_on_error control output behavior. ```bash UBSAN_OPTIONS="print_stacktrace=1:halt_on_error=0:log_path=ubsan.log" \ ./build_ubsan/turboocr-server ``` -------------------------------- ### Run Catch2 tests with tag filter Source: https://github.com/aiptimizer/turboocr/blob/main/docs/dev/testing.md Runs only tests tagged with [serialization] using Catch2's tag filter syntax. ```bash ./build/turbo_ocr_tests "[serialization]" ``` -------------------------------- ### CMake configuration and build for GPU image Source: https://github.com/aiptimizer/turboocr/blob/main/docs/build/docker.md CMake configuration and build commands used in the GPU Dockerfile, with TensorRT directory and options to skip model fetching and fastpdf2png build. ```bash cmake .. -DTENSORRT_DIR=/usr/lib/x86_64-linux-gnu -DFETCH_MODELS=OFF -DTURBO_BUILD_FASTPDF2PNG=OFF make -j$(nproc) ``` -------------------------------- ### Run TSan server Source: https://github.com/aiptimizer/turboocr/blob/main/tests/TESTING_GUIDE.md Run the server with TSan options to log race reports to tsan.log. Set history_size and second_deadlock_stack for detailed diagnostics. ```bash TSAN_OPTIONS="history_size=7:second_deadlock_stack=1:log_path=tsan.log" \ ./build_tsan/turboocr-server ``` -------------------------------- ### Run benchmark scripts for speed, VRAM, and accuracy Source: https://github.com/aiptimizer/turboocr/blob/main/docs/resources_speed_accuracy.md Commands to reproduce the benchmark numbers: speed/VRAM matrix, regression gate, accuracy scoring, and VL-only full page. Requires specific environments and servers as noted. ```bash # Shared 125-doc subset is generated automatically by the harnesses (scripts/omnidoc_subset_n.py). # Speed + VRAM matrix (boots each config, fixed extracted/GT counting) -> result/bench_speed_matrix.{json,md} python3 scripts/bench_speed_matrix.py --n 125 --pool-sizes 2 --concurrency 8 python3 scripts/bench_speed_matrix.py --baseline result/bench_speed_matrix.json # regression gate (>15%) # Accuracy — boot a server with the config, then score (needs omnidocbench/.venv): # local: TABLE_BACKEND=slanext + FORMULA_BACKEND=ppformulanet_s (both auto-resolve # the baked weights; in-process ORT-CUDA-13 — no Python sidecar) # hybrid: TURBO_ROUTING_CONFIG=routing.json (table/formula -> vl), TABLE_SLANEXT_* for slanext_local python3 scripts/omnidoc_run_and_score_n.py --server-url http://localhost:8822 --experiment-name local_125 # VL-only full page (PaddleOCR-VL-1.5 standalone; needs compare-ocrs/.venv + vLLM on :8077) python3 scripts/bench_vl_fullpage.py --subset 125 --server http://localhost:8077/v1 ``` -------------------------------- ### Run clang-tidy Source: https://github.com/aiptimizer/turboocr/blob/main/tests/TESTING_GUIDE.md Commands to build the project and run clang-tidy on single or all source files, with optional fixes. Requires compile_commands.json generated by CMake. ```bash # After building (needs compile_commands.json) cmake -B build -DTENSORRT_DIR=/usr/local/tensorrt cmake --build build -j$(nproc) # Single file clang-tidy -p build src/decode/fast_png_decoder.cpp # All source files find src -name '*.cpp' | xargs -P$(nproc) -I{} clang-tidy -p build {} # With fixes applied (careful -- review first) clang-tidy -p build --fix src/recognition/ctc_decode.cpp ``` -------------------------------- ### Add -fsanitize=address to CMAKE_CUDA_FLAGS Source: https://github.com/aiptimizer/turboocr/blob/main/tests/TESTING_GUIDE.md Compile-time instrumentation for improved detection starting with CUDA 13.1. ```bash # Add to CMAKE_CUDA_FLAGS for instrumented builds -fsanitize=address ``` -------------------------------- ### Run Helgrind Source: https://github.com/aiptimizer/turboocr/blob/main/tests/TESTING_GUIDE.md Use Valgrind's Helgrind tool to check for thread errors. Best used with the CPU-only build due to CUDA incompatibility. ```bash valgrind --tool=helgrind \ --log-file=helgrind.log \ ./build_valgrind/turboocr-cpu-server ``` -------------------------------- ### GET /health/ready Source: https://github.com/aiptimizer/turboocr/blob/main/docs/api/http.md Readiness probe that verifies the pipeline can submit work without blocking. Returns 503 NOT_READY while TensorRT engines are being built on first start. ```APIDOC ## [GET] /health/ready ### Description Readiness probe that verifies the pipeline can submit work without blocking. Returns 503 NOT_READY while TensorRT engines are being built on first start. ### Method GET ### Endpoint /health/ready ### Request Example ```bash curl http://localhost:8000/health/ready ``` ### Response #### Success Response (200) - **Body**: `ok` #### Error Response (503) - **Body**: `NOT_READY` - Returned while the pipeline is not ready (e.g., during engine build). ``` -------------------------------- ### Docker build and run commands Source: https://github.com/aiptimizer/turboocr/blob/main/README.md Build the Docker image with GPU support and run the container with GPU access, exposing ports 8000 and 50051, and mounting a cache volume for TensorRT. ```bash docker build -f docker/Dockerfile.gpu -t turboocr . ``` ```bash docker run --gpus all -p 8000:8000 -p 50051:50051 \ -v trt-cache:/home/ocr/.cache/turbo-ocr turboocr ``` -------------------------------- ### Setup gRPC codegen for protobuf and gRPC Source: https://github.com/aiptimizer/turboocr/blob/main/CMakeLists.txt Macro that discovers protobuf and gRPC, sets up code generation for ocr.proto, and creates custom command to generate protobuf and gRPC sources. Uses macro to propagate variables to calling scope. ```cmake macro(turbo_setup_grpc_codegen) turbo_find_protobuf() find_package(gRPC CONFIG QUIET) if(NOT gRPC_FOUND) find_package(PkgConfig REQUIRED) pkg_check_modules(GRPC REQUIRED grpc++ grpc) set(GRPC_LIBRARIES ${GRPC_LINK_LIBRARIES}) find_program(GRPC_CPP_PLUGIN grpc_cpp_plugin) else() set(GRPC_LIBRARIES gRPC::grpc++) get_target_property(GRPC_CPP_PLUGIN gRPC::grpc_cpp_plugin LOCATION) endif() set(PROTO_SRC_DIR "${CMAKE_SOURCE_DIR}/proto") set(PROTO_GEN_DIR "${CMAKE_BINARY_DIR}/proto_gen") file(MAKE_DIRECTORY ${PROTO_GEN_DIR}) set(PROTO_FILE "${PROTO_SRC_DIR}/ocr.proto") set(PROTO_GEN_CC "${PROTO_GEN_DIR}/ocr.pb.cc") set(PROTO_GEN_H "${PROTO_GEN_DIR}/ocr.pb.h") set(GRPC_GEN_CC "${PROTO_GEN_DIR}/ocr.grpc.pb.cc") set(GRPC_GEN_H "${PROTO_GEN_DIR}/ocr.grpc.pb.h") add_custom_command( OUTPUT ${PROTO_GEN_CC} ${PROTO_GEN_H} ${GRPC_GEN_CC} ${GRPC_GEN_H} COMMAND protobuf::protoc --proto_path=${PROTO_SRC_DIR} --cpp_out=${PROTO_GEN_DIR} --grpc_out=${PROTO_GEN_DIR} --plugin=protoc-gen-grpc=${GRPC_CPP_PLUGIN} ${PROTO_FILE} DEPENDS ${PROTO_FILE} COMMENT "Generating protobuf/gRPC sources" ) endmacro() ``` -------------------------------- ### Create GitHub release and upload assets Source: https://github.com/aiptimizer/turboocr/blob/main/docs/models_release_plan.md Creates a release named models-v3.0.0-ppocrv6 with the staged assets. Requires per-turn approval; never run unprompted. An alternative command uploads to an existing tag models-v3.1.0-local. ```bash gh release create models-v3.0.0-ppocrv6 \ --repo / --title "Model weights (PP-OCRv6 pipeline, v3.0.0)" \ --notes "OCR tiers + layout + doc_ori + SLANet-Plus table + PP-FormulaNet-S (+ plus-M)" \ /tmp/models_release/* ``` ```bash gh release upload models-v3.1.0-local /tmp/models_release/* ``` -------------------------------- ### Run pytest suites Source: https://github.com/aiptimizer/turboocr/blob/main/tests/TESTING_GUIDE.md Commands to run the full test suite or specific suites (unit, integration, regression, benchmark) and individual tests. Use --server-url to target a specific server. ```bash # Full suite python tests/run_all.py # Specific suites python tests/run_all.py --suite unit python tests/run_all.py --suite integration python tests/run_all.py --suite regression python tests/run_all.py --suite benchmark # Single test pytest tests/integration/test_ocr_endpoint.py -v -s # Against a specific server python tests/run_all.py --server-url http://remote:8000 ``` -------------------------------- ### GET /health/ready - Readiness probe Source: https://github.com/aiptimizer/turboocr/blob/main/docs/api/http.md Readiness probe. Invokes the readiness_check closure passed in by main.cpp, verifying the pipeline can submit work without blocking. Stays 503 NOT_READY while TensorRT engines are being built on first start. ```bash curl http://localhost:8000/health/ready ``` -------------------------------- ### Fuzz target: base64 decoder (fuzz_base64.cpp) Source: https://github.com/aiptimizer/turboocr/blob/main/tests/TESTING_GUIDE.md Create tests/fuzz/fuzz_base64.cpp. This libFuzzer target feeds arbitrary bytes to turbo_ocr::base64_decode. It is the recommended starting point because base64_decode directly processes untrusted user input with pointer arithmetic. ```cpp #include "turbo_ocr/common/encoding.h" #include #include extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { turbo_ocr::base64_decode(reinterpret_cast(data), size); return 0; } ``` -------------------------------- ### Reproduce OmniDocBench benchmark Source: https://github.com/aiptimizer/turboocr/blob/main/docs/benchmarks/omnidocbench.md Four-step bash workflow to reproduce the OmniDocBench benchmark: start the OCR server with table and formula backends, render predictions for all 1651 pages, convert raw JSON to markdown, and run the OmniDocBench scorer. Requires TensorRT library path and specific backend environment variables. ```bash # 1. Start the OCR server with table + formula enabled (else ?tables=1&formulas=1 # below returns 400 ...BACKEND_DISABLED). Backend vars auto-resolve the baked # weights — no model paths needed. LD_LIBRARY_PATH="$HOME/TensorRT-10.15.1.29/lib:$LD_LIBRARY_PATH" \ TABLE_BACKEND=slanext FORMULA_BACKEND=ppformulanet_s \ ./build/turboocr-server --http-port 8000 --log-level warn & ``` ```bash # 2. Render predictions for all 1651 pages (~18 s wall on RTX 5090) timeout 600 python tools/omnidoc_run.py \ --in /path/to/omnidocbench/data/v1.7 \ --out /tmp/omnidoc_predictions/json \ --url 'http://127.0.0.1:8000/ocr/raw?layout=1&reading_order=1&tables=1&formulas=1' ``` ```bash # 3. Convert raw JSON → markdown (uses reading_order[], tables[], formulas[]) timeout 600 python tools/omnidoc_to_md.py \ --in /tmp/omnidoc_predictions/json \ --out /tmp/omnidoc_predictions/md ``` ```bash # 4. Run the OmniDocBench scorer cd /path/to/omnidocbench && \ timeout 1800 python -m src.runtime.evaluator \ --config configs/end2end_paddle_optim.yaml \ --predictions /tmp/omnidoc_predictions/md \ --tag md_quick_match ``` -------------------------------- ### Build recipe (clean) Source: https://github.com/aiptimizer/turboocr/blob/main/docs/resources_speed_accuracy.md CMake build command for a clean build with TensorRT and model fetching disabled. ```bash cmake -S . -B build -DCMAKE_BUILD_TYPE=Release -DTENSORRT_DIR= -DFETCH_MODELS=OFF ``` -------------------------------- ### OCR PDF request in bash, python, and javascript Source: https://github.com/aiptimizer/turboocr/blob/main/docs/api/http.md Send a PDF for OCR with mode=auto, dpi=150, and layout=1. The bash example uses curl; the python example uses requests; the javascript example uses fetch. ```bash curl -X POST 'http://localhost:8000/ocr/pdf?mode=auto&dpi=150&layout=1' \ --data-binary @doc.pdf -H 'Content-Type: application/pdf' ``` ```python import requests with open("doc.pdf", "rb") as f: r = requests.post( "http://localhost:8000/ocr/pdf", params={"mode": "auto", "dpi": 150, "layout": 1}, data=f.read(), headers={"Content-Type": "application/pdf"}, ) ``` ```javascript const bytes = await (await fetch("doc.pdf")).arrayBuffer(); await fetch("http://localhost:8000/ocr/pdf?mode=auto&dpi=150&layout=1", { method: "POST", headers: {"Content-Type": "application/pdf"}, body: bytes, }); ``` -------------------------------- ### Run fetch_release_models.sh Source: https://github.com/aiptimizer/turboocr/blob/main/docs/build/models.md For native builds, run the fetcher once by hand to download release models. Re-running is idempotent; SHA-256 verification rejects any asset that drifts from pinned hashes. ```bash bash scripts/fetch_release_models.sh ``` -------------------------------- ### dispatch_router_ short-circuit logic (ocr_pipeline.cpp) Source: https://github.com/aiptimizer/turboocr/blob/main/docs/architecture/router.md Shows the early-return guards and router invocation in ocr_pipeline.cpp. The router is skipped if it is null or the layout is empty, then the plan is cleared before classification. ```cpp // cua_router.h via ocr_pipeline.cpp:9 — router lives in turbo_ocr::router // dispatch_router_ short-circuits — plan 04 §7 invariant 3 if (!router_) return; // ocr_pipeline.cpp:436 if (out.layout.empty()) return; // ocr_pipeline.cpp:437 plan_.clear(); // ocr_pipeline.cpp:440 router_->classify(boxes, out.layout, plan_);// ocr_pipeline.cpp:441 ``` -------------------------------- ### ls -l command Source: https://github.com/aiptimizer/turboocr/blob/main/tests/fixtures/pdf/multi_column.pdf Lists files with details. Output shows file.txt with size 8 bytes. ```bash ls -l ``` ```text -rw-r–r– 1 human human 8 Sep 10 10:56 file.txt ``` -------------------------------- ### JavaScript HTTP GET request using XMLHttpRequest Source: https://github.com/aiptimizer/turboocr/blob/main/tests/fixtures/pdf/multi_column.pdf Shows how to make a GET request with the JS HTTP API using XMLHttpRequest. The code is presented in a table format in the source, with the request URL and status check. ```javascript var request = new XMLHttpRequest(); request.open('GET', '/url/to/resource', true); request.onload = function() { if (request.status >= 200 && request.status < 400) { // Success! } else { // Error! } }; request.send(); ``` -------------------------------- ### GET /metrics Source: https://github.com/aiptimizer/turboocr/blob/main/README.md Prometheus metrics. Returns metrics in Prometheus format. ```APIDOC ## [GET] /metrics ### Description Prometheus metrics. Returns metrics in Prometheus format. ### Method GET ### Endpoint /metrics ### Response #### Success Response (200) Prometheus metrics. #### Response Example # HELP ocr_requests_total Total number of OCR requests # TYPE ocr_requests_total counter ocr_requests_total 100 ``` -------------------------------- ### Point fetch script at new release base Source: https://github.com/aiptimizer/turboocr/blob/main/docs/models_release_plan.md Sets MODELS_RELEASE_URL to the new release download URL and runs the fetch script. No consumer code changes are needed. ```bash MODELS_RELEASE_URL=https://github.com///releases/download/models-v3.1.0-local \ scripts/fetch_release_models.sh ``` -------------------------------- ### Request OCR with Layout, Tables, and Formulas Source: https://github.com/aiptimizer/turboocr/blob/main/README.md Sends a request that enables layout, tables, and formulas. The comment lists alternative endpoints for PDF, Markdown, and gRPC. ```bash curl -X POST "http://localhost:8000/ocr/raw?layout=1&tables=1&formulas=1" \ --data-binary @paper.png -H "Content-Type: image/png" # PDF: POST /ocr/pdf · PDF → Markdown: POST /ocr/pdf?markdown=1 · page → Markdown: POST /ocr/markdown · gRPC: port 50051 ``` -------------------------------- ### GET /capabilities Source: https://github.com/aiptimizer/turboocr/blob/main/docs/api/http.md Returns the server's capabilities, such as available features and build type. ```APIDOC ## [GET] /capabilities ### Description Returns the server's capabilities, such as available features and build type. ### Method GET ### Endpoint /capabilities ### Parameters None ### Response #### Success Response (200) - **capabilities** (object) - Server capabilities. #### Response Example { "capabilities": {} } ``` -------------------------------- ### CPU-only build: find or fetch ONNX Runtime Source: https://github.com/aiptimizer/turboocr/blob/main/CMakeLists.txt In CPU-only mode, prefers a system-installed ONNX Runtime (Docker installs to /usr/local/lib). If not found, uses FetchContent to download the same pinned tarball as docker/Dockerfile.cpu. The vendored third_party/onnxruntime is x86_64; on aarch64 it is the wrong arch, so only /usr/local or a fresh arch-matched fetch is trusted. Requires ORT_SHA256 to be set unless ALLOW_UNVERIFIED_ORT=ON. ```cmake if(USE_CPU_ONLY) message(STATUS "Building CPU-ONLY mode (ONNX Runtime backend)") # Prefer system-installed ORT (Dockerfile installs to /usr/local/lib). # If not found, FetchContent downloads the same pinned tarball as # docker/Dockerfile.cpu so native CPU builds stay reproducible. # The vendored third_party/onnxruntime is x86_64. On x86_64 it is preferred; # on aarch64 it is the wrong arch, so trust only /usr/local (Docker installs # the right arch there) or a fresh arch-matched fetch. if(TURBO_ARCH STREQUAL "x64") set(_ort_tp_lib ${CMAKE_SOURCE_DIR}/third_party/onnxruntime/lib) set(_ort_tp_inc ${CMAKE_SOURCE_DIR}/third_party/onnxruntime/include) else() set(_ort_tp_lib "") set(_ort_tp_inc "") endif() find_library(ONNXRUNTIME_LIB onnxruntime HINTS /usr/local/lib ${_ort_tp_lib}) find_path(ONNXRUNTIME_INCLUDE_DIR onnxruntime_cxx_api.h HINTS /usr/local/include ${_ort_tp_inc}) if(NOT ONNXRUNTIME_LIB OR NOT ONNXRUNTIME_INCLUDE_DIR) include(FetchContent) set(ORT_VERSION "1.22.0" CACHE STRING "ONNX Runtime version to fetch") # SHA256 of onnxruntime-linux--${ORT_VERSION}.tgz, per architecture # (the same values docker/Dockerfile.cpu pins). Bumping ORT_VERSION means # passing -DORT_SHA256=... for the new tarball; an empty hash is a hard # error rather than a silent unverified download — set # ALLOW_UNVERIFIED_ORT=ON to override. if(TURBO_ARCH STREQUAL "x64") set(ORT_SHA256 "8344d55f93d5bc5021ce342db50f62079daf39aaafb5d311a451846228be49b3" CACHE STRING "ONNX Runtime tarball SHA256") else() set(ORT_SHA256 "bb76395092d150b52c7092dc6b8f2fe4d80f0f3bf0416d2f269193e347e24702" CACHE STRING "ONNX Runtime aarch64 tarball SHA256") endif() set(_ort_url "https://github.com/microsoft/onnxruntime/releases/download/v${ORT_VERSION}/onnxruntime-linux-${TURBO_ORT_URL_ARCH}-${ORT_VERSION}.tgz") message(STATUS "ONNX Runtime not found; fetching v${ORT_VERSION} (${TURBO_ORT_URL_ARCH})") if(ORT_SHA256 STREQUAL "") if(NOT ALLOW_UNVERIFIED_ORT) message(FATAL_ERROR "ORT_SHA256 unset for ${TURBO_ARCH}: refusing to fetch ONNX Runtime " "without hash verification. Pin the tarball hash with -DORT_SHA256= " "(see third_party/VERSIONS.md), or pass -DALLOW_UNVERIFIED_ORT=ON to " "explicitly accept an unverified download.") endif() message(WARNING "ALLOW_UNVERIFIED_ORT set; fetching ONNX Runtime for ${TURBO_ARCH} without hash verification") FetchContent_Declare(onnxruntime_prebuilt URL "${_ort_url}" SOURCE_DIR ${CMAKE_SOURCE_DIR}/third_party/onnxruntime) else() FetchContent_Declare(onnxruntime_prebuilt URL "${_ort_url}" URL_HASH SHA256=${ORT_SHA256} SOURCE_DIR ${CMAKE_SOURCE_DIR}/third_party/onnxruntime) endif() FetchContent_MakeAvailable(onnxruntime_prebuilt) find_library(ONNXRUNTIME_LIB onnxruntime HINTS ${CMAKE_SOURCE_DIR}/third_party/onnxruntime/lib REQUIRED) find_path(ONNXRUNTIME_INCLUDE_DIR onnxruntime_cxx_api.h HINTS ${CMAKE_SOURCE_DIR}/third_party/onnxruntime/include REQUIRED) endif() message(STATUS "ONNX Runtime: ${ONNXRUNTIME_LIB}") # Protobuf + gRPC discovery + proto codegen (shared with the GPU arm). turbo_setup_grpc_codegen() ``` -------------------------------- ### GET /health/* Source: https://github.com/aiptimizer/turboocr/blob/main/docs/index.md Health check endpoints for the service. These endpoints provide status information about the service. ```APIDOC ## GET /health/* ### Description Health check endpoints for the service. These endpoints provide status information about the service. ### Method GET ### Endpoint /health/* ### Response #### Success Response (200) - **status** (string) - Health status of the service. #### Response Example { "status": "ok" } ``` -------------------------------- ### GET /health/live - Liveness probe Source: https://github.com/aiptimizer/turboocr/blob/main/docs/api/http.md Liveness probe. Always returns 200 ok once the process is up. ```bash curl http://localhost:8000/health/live ``` -------------------------------- ### GET /health/live Source: https://github.com/aiptimizer/turboocr/blob/main/docs/api/http.md Kubernetes-friendly liveness probe. Returns a simple status indicating the server is alive. ```APIDOC ## [GET] /health/live ### Description Kubernetes-friendly liveness probe. Returns a simple status indicating the server is alive. ### Method GET ### Endpoint /health/live ### Parameters None ### Response #### Success Response (200) - **status** (string) - Health status, e.g., "ok". #### Response Example { "status": "ok" } ``` -------------------------------- ### pwd command Source: https://github.com/aiptimizer/turboocr/blob/main/tests/fixtures/pdf/multi_column.pdf Prints the current working directory. Output shown: /home/human. ```bash pwd ``` ```text /home/human ``` -------------------------------- ### Send test request to server Source: https://github.com/aiptimizer/turboocr/blob/main/tests/TESTING_GUIDE.md Send a POST request to the OCR endpoint with a test image. ```bash curl -X POST http://localhost:8000/ocr/raw \ --data-binary @tests/test_data/png/simple_text.png \ -H "Content-Type: image/png" ```