Skip to content
Microcosmos22Public

About

LLM pipeline to solve complex ARC-AGI problems, built from scratch

Resources

Stars

1 star

Watchers

0 watching

Forks

Repository files navigation

ARC-AGI with Qwen LoRA - A project built from scratch

Motivation

The ARC competition challenges the efficiency of Machine Learning by providing a set of very few training problems, pushing current algorithms towards Artificial General Intelligence. By using LoRa layers on top of a Qwen LLM Model, we transform the problem into a text query-answer problem and can therefore leverage the immense reasoning capabilities of a LLM like Qwen. The winning 2025 solution solves 50% of the tasks with relatively little training (1 epoch) and is based on a token-by-token solution which is combinatorially explored via a best-first DFS search algorithm.

We provide an alternative approach, coded from scratch, training LoRA adapters on top of a Qwen-LLM, however we generate full-grid solutions which we choose according to a beam-search algorithm. We manage to solve 22% of the tasks but have to train each example until the StopLoss criterion is reached, this can take about 30 epochs (4 minutes), sometimes surpassing the expected computing time of 1 minute. The notebook and their output can be found at (https://www.kaggle.com/code/andreshzapke/starter-notebook-qwen-lora-stop-loss) and was built from scratch. We managed to get 12 forks, but abandoned the project due to restraints on the computing time (<12h for 400 tasks).

Instead of training a model on the complete ARC dataset, this project follows the original ARC philosophy: learn from the few demonstrations contained in a single task, then immediately infer the hidden test output.

Alternative text description

Problem

We need to transform the problem into text and prepare a training set of querys-answers that can be fed into the LoRa layers. These will be then trained until we reach a StopLoss criterion to find the correct spot between underfit and overfit. We defined this criterion to be the training step at which all training examples are inferenced correctly, that is $f(X_{train}) = Y_{pred} \equiv Y_{train}$. Note that the example task expects to extend the 2x2 grid pattern to a 6x6 grid:

"<|im_start|>system\n"
"You are an AI trained for the ARC-AGI competition. "
"Given the input grid, predict the full grid solution. "
"Rows are separated by newlines and columns by spaces."
"<|im_end|>\n"
"<|im_start|>user\n"
"Input:\n"

32
78

"<|im_end|>\n"
"<|im_start|>assistant\n"
Output:
323232
787878
232323
878787
323232
787878
"<|im_end|>"

Pipeline

ARC Task
     │
     ▼
Data Augmentation
     │
     ▼
Prompt Generation
     │
     ▼
LoRA Fine-tuning (Qwen)
     │
     ▼
Beam Search Inference
     │
     ▼
Grid Parsing + Evaluation

The repository focuses on exploring how modern LLMs can perform symbolic reasoning by treating ARC grids as sequences of tokens.

Main Techniques

1. Task-specific LoRA Fine-tuning

We will add Low-Rank adaptation layers on top of the LLM to fine-tune to each tasks without changing the original model. To this end, we augment the original model $\theta_T$ parameters by a set of equally dimensioned parameters $\Delta W$ so that the combined model becomes $\theta_F = \theta_T + \Delta W$. Then we can approximately decompose (low-rank approximation) $\Delta W \approx B^TA$ into a column times row multiplication, drastically reducing the number of needed parameters, and therefore the computational time of a backward pass. See (https://www.youtube.com/watch?v=hwounCHi9zQ&t=1s) for a in-depth explanation.

Alternative text description

Advantages:

  • Can be trained on extremely small datasets
  • Adapts to each current task, then throw away
  • Fast training
  • Avoids catastrophic forgetting
  • Only LoRA adapters are updated

2. Prompt Engineering

We convert the training in-out grids into string sequences and insert them into the training prompt shown above. Due to the large number of training steps in our approach, the model quickly learns how the grid outs should be formatted (use newlines to separate rows, use End-Of-Sequence (EOS) token <|im_end|> at the end etc. We also purposedly restrict the token vocabulary that can be used by the model to help him narrow down the space of correct solutions. This technique becomes very important for the token-by-token approach, since they only use one training step for efficiency. Additionally, the token-by-token solution search has a long list of grid consistency checks, further constraining the solutions that the model may retrieve.

After training, the model will only see queries such as:

"<|im_start|>system\n"
"You are an AI trained for the ARC-AGI competition. "
"Given the input grid, predict the full grid solution. "
"Rows are separated by newlines and columns by spaces."
"<|im_end|>\n"
"<|im_start|>user\n"
"Input:\n"
07770
07070
07770
"<|im_end|>\n"
"<|im_start|>assistant\n"

and has to complete the token sequence and end it with a End-of-Sequence. To further improve learning efficiency, we use a DataCollator to explicitly mask which parts of the text belong to the query and the prompt.

3. Data Augmentation

Only augmentations that do not break the semantics and high-level information of the task are allowed. This include Identity, Horizontal flip, Vertical flip and Transpose. The largest augmentation comes from decomposing each task to a token-by-token prediction. This is, we have to slice through the partial output grid and create one prompt per slicing, for example:

"Input:\n"

32
78

Partial Output:
323232
7878

"<|im_end|>\n"
"<|im_start|>assistant\n"
Predicted next token:
7
"<|im_end|>"

For a 6x6 output grid of 36 digits, we can make 36 different partial grids + next token combinations, obtaining a x36 times as many examples as before, one for each slicing/decomposition of the output grid. This results in a huge augmentation of the training examples, but comes with some downsides. The original 2025 solution only trains one epoch over this examples, so the model struggles to learn the formatting. Special care must be put to constrain the possible solution tokens (allow only digits, space, newline or EOS). Additionally, a series of checks must be passed by the partial grid, further heling the model converge to valid grid continuations.

4. Custom Data Collator

The custom collator masks the prompt and computes loss only on the assistant answer, allowing the prompt to serve purely as context.

5. Beam Search, DFS and best-first DFS

Inference uses beam search to generate multiple candidate grids instead of relying on a single solution. That is, at each inference we are able to retrieve possible_solutions = model.generate(**inputs, temperature=0.4, num_return_sequences=8) 8 different solutions, each with a model confidence of that solution given by log_probs = torch.log_softmax(logits, dim=-1). This will be useful later on with the token-by-token solution, where each continuation token has a probability.

To compensate for the short training, the DFS algorithm explores the grid one digit at a time, doing all the combinatorial work and checking the probabilites of each of the paths:

Alternative text description

This works well but might take a very long time due to exploring all of the solution space. The next step is then to implement a best-first DFS, that prevents the algorithm to get stuck on low probability branches. We did get this far in our notebook, however due to GPU per-week and per-task usage constraints, we had to abandon the project.

7. Evaluation

Predicted grids are compared with the hidden labels to compute task accuracy. With our one-shot approach, we managed to solve 22% of the tasks, as opposed to 55% of the token-by-token. With a runtime of around 40h, we are well above the maximum allowed by Kaggle (12h for this competition). We guess this was the starting point of the 2025 solution, who noticed that the main bottleneck and time-consuming part is the training. We are however not interested in sparing resources but on solving scientific tasks and learning new techniques for solving problems.


Current Status

Implemented:

  • ✅ Qwen LoRA fine-tuning
  • ✅ Task-specific training
  • ✅ ChatML prompt generation
  • ✅ ARC data augmentation
  • ✅ Custom masking data collator
  • ✅ Beam search decoding
  • ✅ Automatic evaluation
  • ✅ Grid parsing

Tested but not finished:

  • DFS search of all solution space, but takes too long to compute
  • Validating partial grids works
  • Branch exploration and pruning
  • Pruning helps reject badly formatted output grids

Future Work

Even implementing best-first DFS, the forward passes take too long to compute. The problem is simply that the prompts are very long. Since we obtain a next token, we have to extend the partial grid with the next token, then re-embed the whole prompt before making the next prediction - and this at each step of the DFS best-first search. We would like to use some kind of embedded prompt cache, however new problems arise: The new partial grid is located right in the middle of the prompt. Because embedding of prompts is not assured to be one-token-per-character, inserting the new tokenized digit in the middle of the embedding vector becomes non-trivial. This has been solved by 2025 solution but is deeply technical and we will not further explore this option.

KV Cache

Reuse transformer key/value states during decoding to dramatically reduce inference time and make deeper search practical.

About

LLM pipeline to solve complex ARC-AGI problems, built from scratch

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages