IC-Imajev: Running a 4B Decision Model in a Canister

Hi everyone,
I’d like to introduce IC-Imajev, an implementation of Imajev-4B’s text decision path on the Internet Computer.

The project runs all 32 layers of Qwen3.5-4B, its decision LoRA, and a dedicated readout inside a canister using a Rust/Wasm runtime.
All inference runs within the canister, without calling an external inference API.

Imajev is a decision model that takes evidence, a question, and a set of choices, then scores those choices directly.
A dedicated output layer, or readout, computes the scores from the hidden representation at the decision position at the end of the input.
There is no need to generate an answer as text and then classify it.

This implementation focuses on the text decision path and does not use the vision encoder.

The public app runs inference through ordinary query calls.

Why Decision Models Fit the IC

Running a model inside an IC canister requires organizing its computation around per-call instruction limits, memory constraints, and communication costs.
A decision model such as Imajev reads an input and directly evaluates predefined choices. I think this fits the environment well because the computation can focus on producing a structured decision.

Free-form text generation repeats model computation for each output token.
Imajev processes the input through all 32 layers, then computes choice scores from the hidden representation at the final decision position. This avoids the repeated computation needed to generate an answer token by token.
With a bound on input length, the computation is easier to estimate independently of generated answer length, and the response can stay small: choices and scores.

Predefined choices also fit naturally into canister applications.
For example, an application can use a structured result such as “meets the conditions / does not meet the conditions,” or a support routing category, to choose its next action.
When scores are low or evidence is insufficient, the application can route the case for further review according to its own criteria.

Imajev’s Architecture on Qwen3.5-4B

The Qwen3.5-4B Base Model

Qwen3.5 is a model family released by the Qwen team.
Qwen3.5-4B has approximately four billion parameters. The original model is a generative model with a vision encoder for images and video in addition to text.
IC-Imajev implements its 32 text-processing layers. Qwen3.5-4B model card

The 4B text model uses a dense architecture, with a hidden dimension of 2,560 and a feed-forward network (FFN) intermediate dimension of 9,216 per layer.
Its defining structure is eight repetitions of a block containing three Gated DeltaNet linear-attention layers and one gated full-attention layer.
That gives 24 linear-attention layers and eight full-attention layers. Configuration at the pinned revision

Gated DeltaNet incorporates past information into a recurrent state, which is updated and used for the next token.
Full attention retains keys and values from past tokens and computes attention against the current token’s query vector.
Because the model combines both, pausing and resuming inference requires managing both DeltaNet state and attention K/V.
IC-Imajev’s prefix reuse and execution splitting are built around this architecture.

The Decision Weights Added by Imajev

Qwen provides the base for processing the input. Imajev adds a LoRA adapter trained for decision tasks and a dedicated readout.
In the pretrained version used here, the base weights were frozen while the LoRA and readout were trained.
No additional training was performed for this project.

LoRA adds corrections to the base projections through small A/B matrices.
The adapter used here has rank 64 and alpha 128, allowing the base weights and decision-specific corrections to be handled separately.

The readout is a 256 × 2,560 F32 matrix, covering 255 choice codes and an unknown outcome for insufficient evidence.
After all 32 layers, final RMSNorm normalizes the hidden representation at the final decision position. Scores are then computed from the readout rows corresponding to the choice codes used in the question.
This decision readout replaces Qwen’s full-vocabulary output and text generation.

Input tokens
    ↓
All 32 Qwen3.5-4B layers + decision LoRA
    ↓
Hidden state at the final decision position → final RMSNorm
    ↓
Imajev readout → scores for the choices and unknown

A Dedicated Inference Runtime for the IC

IC-Imajev uses a dedicated Rust runtime for a fixed version of Imajev’s text decision path.
The model operations are compiled to Wasm and invoked through canister entry points.
Using the pretrained weights and model architecture, I implemented the numerical operations, weight layouts, and intermediate state representations needed to run on the IC.

Why Build a Custom Runtime?

On the IC, feasibility depends on more than the model’s total memory footprint. The instruction budget of each call, where computation can be paused, and how much intermediate state must be transferred all matter.
This required a runtime that could divide the forward pass into units that fit the IC’s budgets, preserve intermediate state, and resume computation.

For example, when a matrix multiplication exceeds the instruction budget, the runtime splits it by tokens or output rows while retaining partial sums and progress.
Splitting too finely increases calls and communication, so operations that fit within the budget are fused.
The dedicated runtime controls this splitting, resumption, and fusion across Qwen3.5’s attention and DeltaNet operations, LoRA, and the decision readout.

From Numerical Kernels to All 32 Layers

Alongside INT8 matrix multiplication, the runtime implements the other operations that make up the model.
It connects input quantization, F32 LoRA projections, RMSNorm, SiLU, partial RoPE, causal convolution, attention, Gated DeltaNet recurrent state updates, final normalization, and readout.
Base projection weights and inputs use INT8 arithmetic, while LoRA and readout computation use F32.

Base projections use integer dot products in groups of 256 elements followed by scale application.
Wasm SIMD allows weight reads to be shared across multiple outputs.
Fixed weights are checked and rearranged before inference to reduce reconstruction and copying during execution.
Attention K/V, DeltaNet state, matrix multiplication partial sums, and other intermediate values are managed in a form that can be passed to the next stage.

The weight pack for the text path is approximately 4.70 GB.
This is the size of the stored model data, distinct from runtime heap usage.
The runtime manages the weight pack in stable memory separately from the prepared weight cache and working arrays.

Responsibilities of the Components

The implementation separates responsibilities as follows:

Component Responsibility
Shared numerical components F32 projections, BF16 operations, and lossless codecs independent of model names and IC APIs; native and Wasm SIMD128 support
Model runtime INT8 projections, LoRA, attention, DeltaNet, MLP, weight layouts, intermediate state management, and operation dispatch
Inference canister Weight installation and preparation, stable memory and heap management, authorization, billing, and query/update entry points
Execution control Operation dependencies, budget-aware splitting, continuation, and completion; handled by the client for queries and by the canister for updates

Two Inference Paths: Update and Query

IC-Imajev provides update inference and ordinary query inference.
Both compute all 32 layers of the same decision model. They differ in where intermediate state and continuation are managed.

The update path is designed to integrate the decision model into another canister’s workflow.
The inference canister retains intermediate state and completes the computation through multiple internal calls.
A caller canister attaches cycles to an inference request and receives the result in the response.
This is the primary path for application integration.

The ordinary query path is designed to let a browser or external client drive the computation and inspect intermediate state and execution metrics.

How Update Inference Works

Inference proceeds through the operations of all 32 layers, but running the entire computation in one update call exceeds the instruction limit.
The inference canister therefore splits the work across multiple internal update calls according to the instruction budget.
A worker is the method that handles one of these internal update calls.
The canister invokes workers sequentially through update calls to itself.

Splits are not limited to layer boundaries.
One worker can process multiple layers, while an expensive layer can be split across several workers.
For example, a layer’s attention or DeltaNet operations and its MLP operations can run in separate workers.
For longer inputs, operations within a layer are split into groups of tokens, carrying the required state forward.

Each worker saves intermediate computation state and the next execution position inside the canister.
The next worker resumes from that point. The final stage computes the final normalization and readout and returns the decision.

Inference request accepted
    ↓
Worker 1: compute → save intermediate state
    ↓ self-call
Worker 2: continue from saved state
    ↓
…
    ↓
Final norm / readout → decision result

One update call from the caller serves as the entry point, while the inference canister manages multiple internal update calls.
It waits for each worker to finish before invoking the next. Once computation is complete, it returns the result as the response to the original call.
From the caller’s perspective, this is a single “request inference and receive the result” call.

The current update implementation supports inputs of up to 1,024 tokens, including the evidence text, question, choices, and chat template.
This includes the five-token fixed prefix, leaving a maximum suffix of 1,019 tokens.

Before the prefix was shortened, update testing completed 11 inputs ranging from 70 to 512 tokens, including a fixed 27-token prefix.
Each input required one external inference request. The number of internal worker calls varied with input length and computation.
Representative measurements are shown below.

Total input tokens Internal worker calls Elapsed time Total measured instructions
84 4 27.32 s 121.67B
116 7 53.80 s 187.08B
256 16 123.40 s 490.60B
512 34 257.52 s 1,064.46B

The 512-token input reached a peak heap size of 4,203,151,360 bytes, leaving approximately 87.6 MiB below 4 GiB.
The largest observed instruction count for a worker was 33.53B, and all update calls completed.
Shorter inputs use operations over the full token batch; longer inputs split tokens within individual operations and carry state between steps.

These are local measurements using test inputs of different lengths. Model and prefix preparation costs are excluded.

How Query Inference Works

With ordinary queries, a client such as a browser calls multiple query methods in sequence to compute all 32 layers.
The client handles input formatting and tokenization, execution plan selection, and the validation and transfer of intermediate state. Model operations such as matrix multiplication, attention, DeltaNet, and MLP run on the canister.

Computation state updated inside a query is not persisted in the canister after the call.
Each query therefore performs its assigned operations and returns the intermediate state needed for the next step.
The client retains that state and passes it as an argument to the next query so computation can resume.

Client: tokenize input and select an execution plan
    ↓ query 1: send input and prefix cache
Canister: compute assigned operations → return intermediate state
    ↓ client: validate response and build the next request
Query 2: pass intermediate state to continue computation
    ↓
…
    ↓ final query
Canister: final norm / readout → return decision result

Query execution can also split computation within layers.
For example, the runtime can generate MLP intermediate values across several queries, then combine the remaining MLP work with the next layer’s attention or DeltaNet operations in a single query.
The current browser implementation selects a validated execution plan based on input token count, keeping instruction counts and response sizes within their limits.
It also uses cached computation for the fixed prefix at each layer and computes the continuation for each input.

The state passed between calls includes hidden representations, attention K/V, DeltaNet recurrent state, and partially computed values.
The client checks the model, weight pack, input, progress, and checksums to keep state from different inputs or weights from being mixed.

Checksums verify state integrity; they do not replace authentication.
The browser separately verifies node signatures and checks the hashes of the pinned module, model, weight pack, and prefix assets.

Reusing Fixed-Prefix Computation

The fixed prefix is the token sequence shared at the beginning of inputs.
Its computation is cached in advance across all 32 layers, allowing each inference to resume from the input-specific suffix.

The current fixed prefix consists of five tokens, from the start of the chat template through State:.
The evidence text, question, and choices that follow are part of the suffix and are computed for each input.
The evidence text is quoted as a JSON string, preserving its whitespace and quotation marks.

The prefix cache for all 32 layers occupies 3,816,448 bytes.
The current browser query configuration supports 6–96 total tokens: a five-token prefix plus a suffix of 1–91 tokens.
Execution splits were remeasured for each input length, and inference itself takes 32–63 query calls.
The browser makes two additional queries to check that the model and weight cache are ready.

Optimizations for the IC

The main optimization areas are weight access, numerical computation, state transfer, and allocation of work across calls.

Area Optimization
Weight access Reconstruct, validate, and arrange fixed weights during preparation updates to reduce per-inference reads and reconstruction
Multiply-accumulate operations Use Wasm SIMD for INT8 dot products in groups of 256 elements, sharing weight reads across tokens and outputs
Repeated computation Reuse quantization, scale calculations, multiplication by LoRA’s A matrices, RoPE coefficients, and other work within the same input
Shared prefix Cache the common initial token sequence across all layers and continue from the remaining tokens for each input
State transfer between queries Use lossless encoding and compression that preserve intermediate bit patterns while reducing transfer size
Work allocation across calls Combine consecutive operations and split work within layers to fit each call’s instruction limit
Final-layer processing Compute only what is needed for the final decision position and continue directly to choice scores, avoiding an intermediate-state response

Prefix reuse reuses the computation of the same initial token sequence.

INT8 quantization and lossless communication compression are handled separately.
Numerical agreement has been verified for communication compression, computation reuse, and operation fusion under the selected quantization scheme.

Try It in the Browser

The public demo lets you enter evidence, a question, and choices and run Imajev on the canister.
It includes three examples for exploring numerical changes, decisions with missing information, and classification among multiple choices.

Example Evidence and question Choices
Value change A monthly fee changes from $10 to $10,000. “Did the price increase?” yes / no
Missing info A parcel has shipped, but its expected delivery date and current location are unknown. “Is the delivery late?” yes / no
Three choices A review says, “The product is perfect. Shipping was terrible.” “What is the overall sentiment?” positive / negative / mixed

You can edit the evidence, question, and choices to explore how the decision changes.
The results show the selected choice, probabilities for each choice, the probability of unknown for insufficient information, and whether the model abstained.
The “Real-world examples” section also includes inputs based on BOOM DAO data.

The demo uses the query path.
The browser drives multiple query calls, while the model computation runs on the IC canister.
It provides an interactive way to try inputs and decisions, alongside the update API used by canisters attaching cycles.
The input limit is 96 tokens, including the evidence, question, choices, and chat template.

Testing Inputs and Decisions on Three BOOM DAO Proposals

Voting Eligibility Changes and Minting in BOOM DAO

In 2025, changes to BOOM DAO’s voting eligibility requirements caused many neurons to lose eligibility. During that period, a small number of neurons were able to approve the minting of new tokens.
A neuron is the mechanism through which tokens are staked to participate in DAO voting.
Voting eligibility also depends on a minimum dissolve delay: the waiting period before a neuron can be dissolved.

The DFINITY Governance team’s analysis describes the following sequence:

  1. Proposal #617 changed voting eligibility. When executed, it raised the minimum dissolve delay from 48 hours to over 54 years. Neurons participating with ordinary lock durations no longer met the requirement.
  2. Proposal #653 was created while the stricter requirement was in effect. Two neurons had set their dissolve delay to 83 years. They were the only eligible neurons when mint proposal #653 was created, giving them 100% of the eligible voting power for that proposal and allowing it to be adopted quickly.
  3. Proposal #620 restored the requirement to 48 hours. The stricter condition lasted just over 20 minutes, but the mint proposal was created during that window, with voting eligibility concentrated in those two neurons.

The analysis attributes #653’s adoption to parameter changes across several proposals and their execution order, rather than a code bug.
The case illustrates why review should consider both the mint itself and preceding proposals that change who can vote.

Why Use BOOM DAO Proposals?

The intended use is to filter proposals and protect DAOs from malicious proposals or changes that could enable a takeover.
The idea is to inspect changes before voting or execution, stop dangerous changes, and route cases with insufficient evidence for further review.
Running these decisions on the IC makes it possible to incorporate such checks into canister workflows.

BOOM DAO was selected to explore this use case with real data.
Its history includes proposals that sharply restrict voting eligibility, proposals that restore conditions, and transfers and minting requests.
Assessing them requires considering how numerical changes affect participation and subsequent decisions within the DAO.

Test Setup

The three cases are #617, which tightens voting requirements; #653, which requests minting; and #656, which lowers the minimum stake and extends the voting period.
The inputs contain the parameters in effect when each proposal was created and its proposed values. They exclude titles, summaries, proposal outcomes, and retrospective explanations of the attack.
Seconds are converted to days or years, e8s to tokens, and large values are expressed using million or thousand to preserve their exact amounts.
For #653, the input also includes the total supply and the recipient’s default account balance before proposal creation. It states that the proposal does not specify a minting purpose or spending restrictions, and that the recipient’s staked assets, other controlled accounts, and voting power are unavailable.

The shared decision policy favors accessible participation and sufficient deliberation while preserving DAO safeguards. It calls for rejecting disproportionate participation barriers or changes that weaken safeguards, and returning unknown when information is insufficient.
This policy was defined for the test, rather than being attributed to BOOM DAO at the time. All three cases use the same question:

Should the DAO approve this proposal? Favor accessible participation and adequate deliberation while preserving safeguards. Reject changes that impose disproportionate participation barriers or materially weaken safeguards. If the available information is insufficient to assess these effects, return unknown.

The ordinary choices are approve and reject. The model’s reserved unknown outcome is treated as abstention by the application. No expected answer for an individual proposal is included in its input.

Inputs range from 285 to 460 tokens, including the question, choices, and chat template. The same model and execution settings were used to run all 32 layers and compute decision scores through the query path of a local canister.
No additional training was performed.

Actual Inputs

Input for #617 (303 tokens)
State: "Assessment time: proposal creation.\nAction: ManageNervousSystemParameters.\nCurrent -> proposed parameters:\nminimum stake to create a neuron: 15 million tokens -> 15 million tokens.\nminimum lock duration to vote: 1 days -> 20 thousand days (54.76 years).\nmaximum dissolve delay setting: 30.4375 days -> 30437.5 days (83.33 years).\ninitial voting period: 1 days -> 1 days.\nrejected proposal fee: 100 tokens -> 100 tokens.\nwait-for-quiet extension setting: 0.5 days -> 0.5 days.\nmaximum age bonus: 25% -> 25%.\nage at maximum age bonus: 91.3125 days -> 91.3125 days.\nmaximum dissolve delay bonus: 1% -> 1%.\nmaximum number of neurons: 200 thousand -> 200 thousand.\nOther parameters are unchanged."
Question: Should the DAO approve this proposal? Favor accessible participation and adequate deliberation while preserving safeguards. Reject changes that impose disproportionate participation barriers or materially weaken safeguards. If the available information is insufficient to assess these effects, return unknown.
A: approve
B: reject
C: unknown
Input for #653 (460 tokens)
State: "Assessment time: proposal creation.\nAction: MintSnsTokens.\nCurrent -> proposed parameters:\nminimum stake to create a neuron: 15 million tokens -> 15 million tokens.\nminimum lock duration to vote: 20 thousand days (54.76 years) -> 20 thousand days (54.76 years).\nmaximum dissolve delay setting: 30437.5 days (83.33 years) -> 30437.5 days (83.33 years).\ninitial voting period: 1 days -> 1 days.\nrejected proposal fee: 100 tokens -> 100 tokens.\nwait-for-quiet extension setting: 0.5 days -> 0.5 days.\nmaximum age bonus: 25% -> 25%.\nage at maximum age bonus: 91.3125 days -> 91.3125 days.\nmaximum dissolve delay bonus: 1% -> 1%.\nmaximum number of neurons: 200 thousand -> 200 thousand.\nOther parameters are unchanged.\nAmount to mint: 250 million tokens.\nRecipient: 4mpab-ayg5c-m2frb-vjja5-b2qbe-5rxgv-33ova-ddjgm-egfav-br5hu-gqe; default ledger account.\nTotal token supply before proposal: 1011.77956579167634 million tokens.\nRecipient default account balance before proposal: 15.83662252 tokens.\nMint purpose and spending restrictions: not specified in the proposal.\nRecipient staked assets, other controlled accounts and voting power: unavailable."
Question: Should the DAO approve this proposal? Favor accessible participation and adequate deliberation while preserving safeguards. Reject changes that impose disproportionate participation barriers or materially weaken safeguards. If the available information is insufficient to assess these effects, return unknown.
A: approve
B: reject
C: unknown
Input for #656 (285 tokens)
State: "Assessment time: proposal creation.\nAction: ManageNervousSystemParameters.\nCurrent -> proposed parameters:\nminimum stake to create a neuron: 15 million tokens -> 5 tokens.\nminimum lock duration to vote: 2 days -> 2 days.\nmaximum dissolve delay setting: 30.4375 days -> 30.4375 days.\ninitial voting period: 1 days -> 3 days.\nrejected proposal fee: 100 tokens -> 100 tokens.\nwait-for-quiet extension setting: 0.5 days -> 0.5 days.\nmaximum age bonus: 25% -> 25%.\nage at maximum age bonus: 91.3125 days -> 91.3125 days.\nmaximum dissolve delay bonus: 1% -> 1%.\nmaximum number of neurons: 200 thousand -> 200 thousand.\nOther parameters are unchanged."
Question: Should the DAO approve this proposal? Favor accessible participation and adequate deliberation while preserving safeguards. Reject changes that impose disproportionate participation barriers or materially weaken safeguards. If the available information is insufficient to assess these effects, return unknown.
A: approve
B: reject
C: unknown

Results

Proposal Model decision approve reject unknown
#617 reject 11.4% 87.7% 0.9%
#653 unknown 0.7% 1.2% 98.1%
#656 approve 73.1% 26.4% 0.5%

The numbers are the model’s output scores for each candidate.

#617 raises the minimum voting lock duration from one day, the value in effect at proposal creation, to approximately 54.8 years. #656 lowers the minimum stake from 15 million to 5 tokens and extends the initial voting period from one day to three days.
#653 requests minting 250 million tokens to a default account against a total supply of approximately 1.012 billion tokens. The default account balance supplied in the input is approximately 15.84 tokens.
Under the shared policy, #617 received reject, #656 received approve, and #653—with information such as the minting purpose and the recipient’s voting power missing—received unknown.

Closing Thoughts

This project successfully ran all 32 layers of a 4B decision model inside an Internet Computer canister, with practical applications in mind.
The BOOM DAO cases produced rejection, abstention, and approval decisions, marking a step toward applications such as DAO proposal review.

In the update path, the inference canister manages multiple internal update calls so that a caller canister can request inference with a single update call.
This provides an execution foundation for incorporating model decisions into other canisters’ workflows.

Next, I plan to prepare calling instructions and examples so anyone can use inference through update calls from their own canister.
The query path is already public and available through the demo site.
I’d welcome feedback on use cases for decision models in canister workflows and on this execution approach.

7 Likes