Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
123 changes: 105 additions & 18 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,64 @@ name: CI

on:
push:
branches: [ main ]
branches: [main]
pull_request:
branches: [ main ]
branches: [main]

env:
CARGO_TERM_COLOR: always
RUSTFLAGS: --deny warnings
RUSTDOCFLAGS: --deny warnings
SLANG_TAG: 2025.18.2

jobs:
# Check formatting.
format:
name: Format
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt

- name: Run cargo fmt
run: cargo fmt --all -- --check
setup-slang:
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
include:
- os-id: linux
os: ubuntu-latest
- os-id: macos-aarch64
os: macos-latest
runs-on: ${{ matrix.os }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- uses: actions/cache@v4
id: cache-slang
with:
path: ~/.cache/slang/slang-v${{ env.SLANG_TAG }}-${{ matrix.os-id }}
key: slang-v${{ env.SLANG_TAG }}-${{ matrix.os-id }}
- name: Download slang
if: steps.cache-slang.outputs.cache-hit != 'true' # Only download on miss
id: setup
run: |
./download_slang.sh --os ${{ matrix.os-id }} --version $SLANG_TAG
# Run clippy lints.
clippy:
needs: setup-slang # Depends on setup-slang
name: Clippy
runs-on: ubuntu-latest
env:
SLANG_DIR: /home/runner/.cache/slang/slang-v2025.18.2-linux
SLANG_CACHE_KEY: slang-v2025.18.2-linux
timeout-minutes: 30
steps:
- name: Checkout repository
Expand All @@ -29,50 +73,93 @@ jobs:
- name: Install dependencies
run: sudo apt-get update; sudo apt-get install --no-install-recommends libwebkit2gtk-4.1-dev build-essential curl wget file libxdo-dev libssl-dev libayatana-appindicator3-dev librsvg2-dev

- name: Retrieve Cache for Slang
uses: actions/cache/restore@v4
with:
path: ~/.cache/slang/slang-v${{ env.SLANG_TAG }}-linux
key: slang-v${{ env.SLANG_TAG }}-linux

- name: Populate target directory from cache
uses: Leafwing-Studios/cargo-cache@v2
with:
sweep-cache: true

- name: Run clippy lints
run: cargo clippy --locked --workspace --all-targets --all-features -- --deny warnings
run: SLANG_DIR=$SLANG_DIR cargo clippy --locked --workspace --all-targets --features web,desktop,mobile,comptime_checks -- --deny warnings

# Check formatting.
format:
name: Format
# Check documentation.
doc:
needs: setup-slang # Depends on setup-slang
name: Docs
runs-on: ubuntu-latest
timeout-minutes: 30
env:
SLANG_DIR: /home/runner/.cache/slang/slang-v2025.18.2-linux
SLANG_CACHE_KEY: slang-v2025.18.2-linux
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable

- name: Install dependencies
run: sudo apt-get update; sudo apt-get install --no-install-recommends libwebkit2gtk-4.1-dev build-essential curl wget file libxdo-dev libssl-dev libayatana-appindicator3-dev librsvg2-dev

- name: Retrieve Cache for Slang
uses: actions/cache/restore@v4
with:
components: rustfmt
path: ~/.cache/slang/slang-v${{ env.SLANG_TAG }}-linux
key: ${{ env.SLANG_CACHE_KEY }}

- name: Run cargo fmt
run: cargo fmt --all -- --check
- name: Populate target directory from cache
uses: Leafwing-Studios/cargo-cache@v2
with:
sweep-cache: true

# Check documentation.
doc:
name: Docs
runs-on: ubuntu-latest
- name: Check documentation
run: SLANG_DIR=$SLANG_DIR cargo doc --locked --workspace --features web,desktop,mobile,comptime_checks --document-private-items --no-deps
# Testing.
testing:
needs: setup-slang
name: Tests
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest]
include:
- slang-dir: /home/runner/.cache/slang/slang-v2025.18.2-linux
os: ubuntu-latest
- slang-dir: /Users/runner/.cache/slang/slang-v2025.18.2-macos-aarch64
os: macos-latest
- slang-cache-key: slang-v2025.18.2-linux
os: ubuntu-latest
- slang-cache-key: slang-v2025.18.2-macos-aarch64
os: macos-latest
runs-on: ${{ matrix.os }}
env:
SLANG_DIR: ${{ matrix.slang-dir }}
SLANG_CACHE_KEY: ${{ matrix.slang-cache-key }}
timeout-minutes: 30
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable

- name: Install dependencies
if: ${{ runner.os == 'linux' }}
run: sudo apt-get update; sudo apt-get install --no-install-recommends libwebkit2gtk-4.1-dev build-essential curl wget file libxdo-dev libssl-dev libayatana-appindicator3-dev librsvg2-dev
- name: Retrieve Cache for Slang
uses: actions/cache/restore@v4
with:
fail-on-cache-miss: true
path: ~/.cache/slang/${{ matrix.slang-cache-key }}
key: ${{ matrix.slang-cache-key }}

- name: Populate target directory from cache
uses: Leafwing-Studios/cargo-cache@v2
with:
sweep-cache: true

- name: Check documentation
run: cargo doc --locked --workspace --all-features --document-private-items --no-deps
- name: Run Cargo Tests
run: |
SLANG_DIR=$SLANG_DIR cargo test --verbose
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,6 @@ fabric.properties
# Android studio 3.1+ serialized cache file
.idea/caches/build_file_checksums.ser

.DS_store
.DS_store

downloaded_slang
13 changes: 10 additions & 3 deletions crates/slai-chat/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,18 @@ This is a basic chat interface for testing **slai**. Currently only supports:
- Qwen 2.
- Segment Anything.

In order to compile and run `slai-chat`, be sure to define the `SLANG_DIR` environment variable:
1. Download the Slang compiler libraries for your platform: https://github.com/shader-slang/slang/releases/tag/v2025.16
2. Unzip the downloaded directory, and use its path as value to the `SLANG_DIR` environment variable: `SLANG_DIR=/path/to/slang`.
In order to compile and run `slai-chat`, be sure to define the `SLANG_DIR` environment variable.

Either:

- Run the script at the root of slai repository: `SLANG_DIR=$(./download_slang.sh | grep '^SLANG_DIR=' | cut -d'=' -f2-)`
- Or manually:
1. Download the Slang compiler libraries for your platform: https://github.com/shader-slang/slang/releases/tag/v2025.16
2. Unzip the downloaded directory, and use its path as value to the `SLANG_DIR` environment variable: `SLANG_DIR=/path/to/slang`.
Note that the variable must point to the root of the slang installation (i.e. the directory that contains `bin` and `lib`).



To run the GUI natively:
```bash
dx run --release --features desktop
Expand Down
5 changes: 1 addition & 4 deletions crates/slai-chat/src/chat_llama2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,7 @@ impl<B: Backend> ChatLlama2<B> {
// Run the transformer.
let mut encoder = backend.begin_encoding();
backend.write_buffer(state.rope_config_mut().buffer_mut(), &[rope_config])?;
backend.write_buffer(
state.rms_norm_config_mut().buffer_mut(),
&[rms_norm_config],
)?;
backend.write_buffer(state.rms_norm_config_mut().buffer_mut(), &[rms_norm_config])?;
backend.write_buffer(state.attn_params_mut().buffer_mut(), &[attn_params])?;
state
.x
Expand Down
22 changes: 10 additions & 12 deletions crates/slai-chat/src/components/chat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -437,18 +437,16 @@ fn submit_prompt<B: Backend>(
let gpu = gpu.clone();
let llm = model.llm.clone();
execute(async move {
llm
.forward(
&gpu.backend,
prompt,
sampler,
chat_template,
next_pos,
|msg| {
Ok(out.unbounded_send(msg)?)
})
.await
.unwrap()
llm.forward(
&gpu.backend,
prompt,
sampler,
chat_template,
next_pos,
|msg| Ok(out.unbounded_send(msg)?),
)
.await
.unwrap()
});
}

Expand Down
1 change: 0 additions & 1 deletion crates/slai-chat/src/components/home.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use crate::chat_template::ChatTemplate;
use crate::llm::ChatLlm;
use crate::{GgufMetadata, GpuInstanceCtx, LoadedModel, LoadedModelSignal, SelectedBackend};
use async_std::sync::RwLock;
use dioxus::prelude::*;
use dioxus_markdown::Markdown;
use rfd::FileHandle;
Expand Down
3 changes: 1 addition & 2 deletions crates/slai-chat/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use crate::cli::Cli;
use crate::llm::ChatLlm;
use crate::prompt::Prompt;
use crate::sampler::SamplerParams;
use async_std::sync::RwLock;
use components::{Chat, Home};
use dioxus::prelude::*;
use slang_hal::backend::Backend;
Expand Down Expand Up @@ -161,7 +160,7 @@ fn App() -> Element {
match (&*gpu_wgpu.read_unchecked(), &*gpu_cuda.read_unchecked()) {
(Some(Ok(gpu_wgpu)), Some(Ok(gpu_cuda))) => {
use_context_provider(|| gpu_wgpu.clone());
use_context_provider(|| gpu_cuda.clone());
use_context_provider(|| *gpu_cuda);
use_context_provider(|| LoadedModelSignal::new(None));
use_context_provider(|| Signal::new(PromptState::default()));

Expand Down
2 changes: 1 addition & 1 deletion crates/slai/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub fn main() {
let out_dir = Path::new(&out_dir);
let autogen_target = out_dir.join("autogen");

for (target, ext) in targets {
for (target, _ext) in targets {
std::fs::create_dir_all(&autogen_target).unwrap();
slang.compile_all(target, "./shaders", &autogen_target, &[]);
}
Expand Down
Loading
Loading