Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
b310d44
Added the skeleton of a C++ module to directly evaluate FTAs using ll…
tristanvdb Aug 1, 2025
8eecae8
Started implementing the base types for autocog::llama C++ module
tristanvdb Aug 1, 2025
2b10b36
Added model with tokenization to autocog::llama C++ module
tristanvdb Aug 1, 2025
3e52461
Added tests for sta->fta and executing STA with LLama.cpp
tristanvdb Aug 1, 2025
10be985
Prototype export of FTA to dict for serialization
tristanvdb Aug 2, 2025
5f336b2
Working on simplest evaluation of FTA
tristanvdb Aug 6, 2025
769d4b8
LLama.cpp went al the way through FTA eval but segfault in FFT to pydict
tristanvdb Aug 7, 2025
aa9539d
Tons of fixes to get to a working implementation
tristanvdb Aug 8, 2025
84486c1
Context reuse based on prefixes. Repetition penalty and diversity bonus.
tristanvdb Aug 9, 2025
95a7dbb
Getting started on integrating C++ work with full Autocog flow
tristanvdb Aug 10, 2025
164d749
Finished integrating C++ evaluation of FTA into complete AutoCog flow…
tristanvdb Aug 10, 2025
ea1f9f7
Stated working on RHEL support (ubi container and setup script)
Aug 12, 2025
f49904c
Added CUDA support
Aug 14, 2025
133842d
Added parameters to control beam search and some minor changes of STA…
tristanvdb Aug 14, 2025
c11cd7e
Added modules/autocog.egg-info/ to .gitignore
tristanvdb Aug 25, 2025
e6ce75f
Temporary disabled deleting llama contexts as it causes a CUDA error
tristanvdb Aug 26, 2025
9cc8282
Added a test harness for laguage parsing
tristanvdb Aug 26, 2025
40d97e6
Started working on a C++ implementation of the parser.
tristanvdb Aug 27, 2025
8dbeca1
Implemented some of the parsing
tristanvdb Aug 29, 2025
19c5851
Made a lot of progress on the C++ parser
tristanvdb Aug 29, 2025
2272adf
Finished the parsing.
tristanvdb Aug 29, 2025
390ce90
Refactoring before next step
tristanvdb Sep 5, 2025
99b8891
Added protobuf implementation of the IR and more namespace refactoring
tristanvdb Sep 5, 2025
bc3340a
Refactor the AST into its own subnamespace
tristanvdb Sep 5, 2025
a2aa434
Major reorganization of all C++ code. Includes CMake reorg.
tristanvdb Sep 5, 2025
f33c90c
Made the pip installation work with the new CMake
tristanvdb Sep 5, 2025
5a3f29a
Finished XFTA executable and fixed the container
tristanvdb Sep 6, 2025
2a5b4a9
Started working on instantiation
tristanvdb Sep 6, 2025
a1b131d
Removed all protobuf work
tristanvdb Sep 6, 2025
4f7e492
Implemented expression evaluation
tristanvdb Sep 9, 2025
734d697
Tried to add some syntax highlight for STL. Got gedit but vscode is r…
tristanvdb Sep 9, 2025
9c6da84
Fixed expression evaluation (and test case)
tristanvdb Sep 9, 2025
072b06a
Improved expression evaluation, generation of symbol tables, and clea…
tristanvdb Sep 10, 2025
e3d4236
Finished symbol resolution
tristanvdb Sep 10, 2025
c82916c
Finished symbol resolution
tristanvdb Sep 10, 2025
f62cc51
Define evaluation with scoped context. Improved source position track…
tristanvdb Sep 11, 2025
f1a17ee
Worked on the C++ IR for STL and remove the EXTERN keyword
tristanvdb Sep 11, 2025
3d272a2
Moved some old files arround in the share/ directory
tristanvdb Sep 12, 2025
31d23ff
Major update to STL with associated demo writer app. Distributed pars…
tristanvdb Sep 13, 2025
a58bafc
Added unit-tests for the STL parser
tristanvdb Sep 14, 2025
7621c8a
[stlc] Added Driver abstraction, traversal mechanism for the AST, bet…
tristanvdb Sep 19, 2025
104e058
STLC] Refactor AST to remove MAPPED children
tristanvdb Sep 19, 2025
d0fe3db
[STLC] Working on proper symbol-table (+ using X-macro pattern to dea…
tristanvdb Sep 26, 2025
3c29046
[Util] Adding exception tracing and nice backtrace to the libraries
tristanvdb Sep 26, 2025
e735c7e
[STLC] Fixed symbol building traversal
tristanvdb Sep 26, 2025
e9f1858
[STLC] Display data when debug enabled
tristanvdb Sep 26, 2025
2d201b1
[STLC] Evaluation of globals and collection of ObjectRef and FormatRef
tristanvdb Oct 1, 2025
319713c
[stlc] Missing template instantiation directive and incorrect ast::Ta…
tristanvdb Oct 1, 2025
f511648
[STLC] Added a bunch of printer (AST and RefNodes) and found a bug in…
tristanvdb Oct 13, 2025
54f3499
[Build] Fix Release mode compilation issues
tristanvdb Dec 2, 2025
e920aaa
[Docs] Update DEVEL.md with modern container-based workflow
tristanvdb Dec 2, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Git
.git
.gitignore

# Python
__pycache__/
*.py[cod]
*$py.class
*.so
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg

# Virtual environments
venv/
env/
ENV/

# IDE
.vscode/
.idea/
*.swp
*.swo

# OS
.DS_Store
Thumbs.db

# Logs
*.log

# Documentation
docs/_build/

# Test coverage
.coverage
htmlcov/

# Temporary files
*.tmp
*.temp

models/

Dockerfile*

*.md
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,13 @@
**/__pycache__/
/models
/Pipfile
/modules/autocog/*.so
/build/
ftt.svg
.venv/
modules/autocog.egg-info/
**/__build

*.sta.json
*.ftt.json
**/DEBUG.log
6 changes: 6 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[submodule "vendors/llama"]
path = vendors/llama
url = https://github.com/ggerganov/llama.cpp.git
[submodule "vendors/reflex"]
path = vendors/reflex
url = https://github.com/Genivia/RE-flex.git
78 changes: 78 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
cmake_minimum_required(VERSION 3.18)
project(autocog)

# Set C++ standard
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Build type" FORCE)
endif()
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo")

if(CMAKE_BUILD_TYPE STREQUAL "Debug")
add_compile_definitions(VERBOSE=1)
add_compile_definitions(DEBUG=1)
else()
add_compile_definitions(VERBOSE=0)
add_compile_definitions(NDEBUG=1)
endif()

set(COMMON_CXX_FLAGS "-Wall -Wextra -Werror")
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
set(CMAKE_CXX_FLAGS_DEBUG "-g -O0 -rdynamic -fno-omit-frame-pointer -Wl,--wrap=__cxa_throw ${COMMON_CXX_FLAGS}")
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG ${COMMON_CXX_FLAGS}")
endif()

find_package(Python COMPONENTS Interpreter Development REQUIRED)
find_package(pybind11 QUIET)
if(NOT pybind11_FOUND)
execute_process(
COMMAND ${Python_EXECUTABLE} -c "import pybind11; print(pybind11.get_cmake_dir())"
OUTPUT_VARIABLE pybind11_DIR
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_QUIET
)
if(pybind11_DIR)
find_package(pybind11 REQUIRED PATHS ${pybind11_DIR})
else()
message(FATAL_ERROR "pybind11 not found. Install with: pip install pybind11")
endif()
endif()

find_program(REFLEX reflex REQUIRED)
find_library(REFLEX_LIB reflex REQUIRED)
find_path(REFLEX_INC
NAMES reflex/flexlexer.h
HINTS /opt/include /usr/local/include
REQUIRED
)

find_library(LLAMA_LIB
NAMES llama
HINTS /opt/lib /opt/lib64 /usr/local/lib /usr/local/lib64
REQUIRED
)

find_path(LLAMA_INC
NAMES llama.h
HINTS /opt/include /usr/local/include
REQUIRED
)

enable_testing()

add_subdirectory(libs/autocog/utilities)

add_subdirectory(libs/autocog/compiler/stl)
add_subdirectory(tools/stlc)
add_subdirectory(bindings/compiler-stl)

add_subdirectory(libs/autocog/llama/xfta)
add_subdirectory(tools/xfta)
add_subdirectory(bindings/llama-xfta)

add_subdirectory(tests/units)

add_subdirectory(share/demos)

143 changes: 143 additions & 0 deletions DEVEL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
# Develop Commands Cheat Sheet

## Get models

```
mkdir -p models
cd models
wget -O SmolLM3-Q4_K_M.gguf https://huggingface.co/ggml-org/SmolLM3-3B-GGUF/resolve/main/SmolLM3-Q4_K_M.gguf?download=true
```

## Container

### CPU (for dev)

Build the image:
```
docker build -t autocog:ubi -f Dockerfile.ubi .
```

Run one-off commands:
```
docker run --rm -v $(pwd):/workspace -w /workspace autocog:ubi scripts/sanity-check.sh
```

**Recommended: Use a persistent container for development:**
```bash
# Start persistent container
docker run -d --name autocog --rm -v $(pwd):/workspace -w /workspace autocog:ubi sleep infinity

# Execute commands in the container
docker exec autocog bash -c "cd /tmp && cmake /workspace && make install && ctest"

# Interactive shell
docker exec -it autocog bash

# Stop container when done
docker stop autocog
```

### CUDA on RHEL with Podman

First setup CUDA for container use (3rd command is for FIPS enable machines):
```bash
curl -s -L https://nvidia.github.io/libnvidia-container/stable/rpm/nvidia-container-toolkit.repo | \
sudo tee /etc/yum.repos.d/nvidia-container-toolkit.repo
sudo dnf --disablerepo=\* --enablerepo=nvidia-container-toolkit-experimental install -y nvidia-container-toolkit
sudo rpm -ivh --nodigest --nofiledigest /var/cache/dnf/nvidia-container-toolkit-experimental-*/packages/*.rpm
sudo nvidia-ctk cdi generate --output=/etc/cdi/nvidia.yaml
sudo chmod o+r /etc/cdi/nvidia.yaml
sudo chmod o+rx /etc/cdi
podman run --rm --device nvidia.com/gpu=all docker.io/nvidia/cuda:12.4.0-runtime-ubuntu22.04 nvidia-smi
```

Build and run persistent container:
```bash
podman build --device nvidia.com/gpu=all -f Dockerfile.ubi-cuda -t autocog:ubi-cuda .
podman run -d --name autocog --rm --device nvidia.com/gpu=all \
-v $(pwd):/workspace -w /workspace autocog:ubi-cuda sleep infinity

# Execute commands
podman exec autocog bash -c "cd /tmp && cmake /workspace && make install && ctest"
```

### Ubuntu with CUDA (Docker)

```bash
docker build -t autocog:ubuntu -f Dockerfile.ubuntu .
docker run -d --name autocog --rm --gpus all \
-v $(pwd):/workspace -w /workspace autocog:ubuntu sleep infinity
```

## Testing Components

### xFTA (Finite Thoughts Automaton Executor)

Testing the C++ utility:
```bash
python3 scripts/dump_sta_to_json.py tests/samples/mini.sta models/SmolLM3-Q4_K_M.gguf
xfta -v -m models/SmolLM3-Q4_K_M.gguf tests/samples/mini.sta.json
```

Testing the integration:
```bash
python3 scripts/execute_sta_with_llama_cpp.py tests/samples/mini.sta '{}' models/SmolLM3-Q4_K_M.gguf
```

### STLC (Structured Thoughts Language Compiler)

Test compilation:
```bash
stlc -h
stlc tests/samples/defines.stl
stlc share/demos/story-writer/story-writer.stl
```

## Building and Testing

### Build Types

**Debug build** (with exception backtrace wrapper):
```bash
mkdir -p /tmp/autocog && cd /tmp/autocog
cmake /workspace -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=/opt
make install -j$(nproc)
```

**Release build** (optimized, default):
```bash
mkdir -p /tmp/autocog && cd /tmp/autocog
cmake /workspace -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/opt
make install -j$(nproc)
```

### Running Tests

Run all tests:
```bash
cd /tmp/autocog
ctest --output-on-failure
```

Run specific test suites:
```bash
ctest -R stl_parser # All parser tests
ctest -R smoke # Smoke tests only
ctest -R stl_parser_identifiers -V # Single test with verbose output
```

Run in persistent container:
```bash
docker exec autocog bash -c "cd /tmp && cmake /workspace -DCMAKE_BUILD_TYPE=Release && make install -j\$(nproc) && ctest --output-on-failure"
```

### Python Package Testing

Install and test the Python package:
```bash
pip install /workspace
python -c "import autocog"
python -c "import autocog.compiler.stl"
python -c "import autocog.llama.xfta"
```

61 changes: 61 additions & 0 deletions Dockerfile.ubi
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
FROM registry.access.redhat.com/ubi9/ubi:latest

ENV PYTHONUNBUFFERED=1

RUN dnf --disablerepo=\* --enablerepo=ubi-\* install -y \
gcc gcc-c++ \
cmake \
pkgconf-pkg-config \
python3 \
python3-pip \
python3-devel \
graphviz && \
dnf clean all

# Venv

RUN python3 -m venv /opt

ENV PATH="/opt/bin:$PATH"
ENV LD_LIBRARY_PATH="/opt/lib:/opt/lib64:/usr/local/lib:/usr/local/lib64:$LD_LIBRARY_PATH"
ENV PYTHONPATH=""

RUN pip install --upgrade pip && \
pip install graphviz

# RE/Flex

COPY vendors/reflex /tmp/reflex

RUN cd /tmp/reflex && \
./build.sh && \
mkdir -p /opt/include/reflex && \
cp lib/*.a lib/*.so /opt/lib && \
cp bin/reflex /opt/bin && \
cp include/reflex/*.h /opt/include/reflex && \
rm -rf /tmp/reflex

# LLama.cpp

COPY vendors/llama /tmp/llama_cpp

RUN cd /tmp/llama_cpp && \
cmake -B build \
-DCMAKE_INSTALL_PREFIX=/opt \
-DLLAMA_BUILD_COMMON=OFF \
-DLLAMA_CUDA=OFF && \
cmake --build build --parallel $(nproc) && \
cmake --install build && \
rm -rf /tmp/llama_cpp

# Autocog

COPY . /tmp/autocog

RUN pip install /tmp/autocog && \
rm -rf /tmp/autocog

ENV PATH="/opt/lib64/python3.9/site-packages/bin/:$PATH"

WORKDIR /workspace

Loading