Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0bc66fd

Browse files
committed
update readme
1 parent bbb155a commit 0bc66fd

4 files changed

Lines changed: 42 additions & 60 deletions

File tree

README.md

Lines changed: 41 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
1-
2-
31
# $\lambda$-RLM
4-
Code for $\lambda$-Recursive Language Models: typed functional recursion for reliable long-context reasoning.
2+
Code for **The $\mathbf{Y}$-Combinator for LLMs: \\ Solving Long-Context Rot with $\lambda$-Calculus**: a framework for long-context reasoning that replaces free-form recursive code generation with a typed functional runtime grounded in $\lambda$-calculus.
3+
4+
<p align="center">
5+
<img src="intro.png" alt="Lambda-RLM results figure" width="900" />
6+
</p>
57

6-
Standard LLM inference is limited by context windows and is opaque — models improvise decomposition unpredictably. $\lambda$-RLM solves this by:
8+
Standard LLM inference is constrained by context windows and often relies on implicit, hard-to-predict decomposition strategies. $\lambda$-RLM addresses this by:
79

8-
- **Pre-computing** the optimal decomposition plan before any LLM call (deterministic)
9-
- **Mapping inference** to Lambda Calculus primitives: β-reduction at leaves, symbolic combinators for composition
10-
- **Splitting** long inputs into parallel chunks where each fits in the model's context window
11-
- **Composing** results via pre-verified operators (MERGE_COUNTS, SEARCH_UNION, SUMMARIZE_REDUCE, etc.)
10+
- **Planning decomposition ahead of execution** with a deterministic recursive strategy
11+
- **Expressing inference through functional structure**, with model calls at local steps and symbolic operators for composition
12+
- **Breaking long inputs into manageable chunks** that fit within the model context window
13+
- **Combining intermediate results** through structured operators such as `MERGE_COUNTS`, `SEARCH_UNION`, and `SUMMARIZE_REDUCE`
1214

1315
---
1416

@@ -22,26 +24,21 @@ conda activate lambda-rlm
2224

2325
pip install -e .
2426
```
25-
We support access models through APIs, for example, you can request a [NVIDIA NIM API key](https://build.nvidia.com) to access available models.
27+
We support access different avaialble models through APIs, for example, you can request a [NVIDIA NIM API key](https://build.nvidia.com) or a [TOGETHER AI API key](https://api.together.ai/) to access available models of the given API.
2628

2729
```bash
2830
export NVIDIA_API_KEY="nvapi-..."
2931
```
3032

33+
```bash
34+
export TOGETHER_API_KEY="tgp_..."
35+
```
3136

32-
### Supported Task Types
33-
34-
| Task | Composition Operator | Strategy |
35-
|---|---|---|
36-
| `aggregation` | MERGE_COUNTS | SPLIT → MAP → sum counts |
37-
| `search` | SEARCH_UNION | SPLIT → MAP → union doc IDs |
38-
| `classification` | CONCAT | SPLIT → MAP → concat labels |
39-
| `pairwise` | CONCAT + symbolic CROSS | MAP(classify) → CROSS(O(N²), free) |
40-
| `summarization` | SUMMARIZE_REDUCE + M | SPLIT → MAP → M(final synthesis) |
41-
| `extraction` | CONCAT | SPLIT → MAP → concat fields |
42-
| `code_understanding` | CONCAT | SPLIT → MAP → concat analysis |
43-
| `multi_hop` | SUMMARIZE_REDUCE + M | SPLIT → MAP(extract) → M(synthesize) |
44-
37+
### Supported datasets:
38+
- `sniah` — Sequential-NIAH examples loaded from the public GitHub JSONL source
39+
- `oolong` — single-document QA examples loaded from `THUDM/LongBench-v2`
40+
- `browsecomp` — multi-document QA examples loaded from `THUDM/LongBench-v2`
41+
- `codeqa` — code repository understanding examples loaded from a local JSONL file or from `THUDM/LongBench-v2`
4542

4643
## Usage
4744

@@ -70,7 +67,7 @@ Answer:"""
7067

7168
rlm = LambdaRLM(
7269
backend_kwargs={
73-
"model_name": "qwen/qwen3-next-80b-a3b-thinking",
70+
"model_name": "meta/llama-3.3-70b-instruct",
7471
"api_key": os.environ["NVIDIA_API_KEY"],
7572
"base_url": "https://integrate.api.nvidia.com/v1",
7673
}
@@ -80,23 +77,32 @@ result = rlm.completion(prompt)
8077
print(result.response)
8178
```
8279

80+
## Repository structure
81+
### Normal RLM
82+
83+
This repository uses upstream Normal RLM components for comparison: `https://github.com/alexzhang13/rlm`
84+
85+
The upstream code is licensed under the MIT License. See `THIRD_PARTY_NOTICES.md` for attribution and licensing details.
86+
87+
Key files:
88+
- `rlm/core/rlm.py` — main REPL-based RLM loop
89+
- `rlm/environments/local_repl.py` — sandboxed Python REPL execution, context storage, and helper functions
90+
- `rlm/utils/parsing.py` — parsing of ```repl``` code blocks and FINAL markers; formatting of execution output back into the model history
91+
- `rlm/clients/openai.py` — OpenAI-compatible client used with NVIDIA NIM
92+
93+
### Lambda-RLM
94+
95+
- `rlm/lambda_rlm.py` — LambdaRLM implementation, including task detection, planning, and deterministic execution through $\Phi$
96+
8397
## Benchmarking
8498

8599
The benchmark entry point is used for running experiments with same dataset and comparing the behavior, latency, and output quality under the same setup between Normal RLM (rlm) and Lambda-RLM (lambda_rlm)
86100

87-
### Supported datasets:
88-
- `sniah` — Sequential-NIAH examples loaded from a local JSONL file or from the public GitHub JSONL source
89-
- `oolong` — single-document QA examples loaded from `THUDM/LongBench-v2`
90-
- `browsecomp` — multi-document QA examples loaded from `THUDM/LongBench-v2`
91-
- `codeqa` — code repository understanding examples loaded from a local JSONL file or from `THUDM/LongBench-v2`
92-
93-
### Supported models:
94-
- todo
95101

96102
### Compare both methods on the same dataset
97103

98104
```bash
99-
python benchmarks/benchmark.py --datasets sniah --methods rlm lambda_rlm --n-samples-per-bucket 1 --max-iter 8 --max-depth 2 --context-window 100000 --output-dir ./results_compare
105+
python benchmarks/benchmark.py --datasets sniah --model meta/llama-3.3-70b-instruct --methods rlm lambda_rlm --n-samples-per-bucket 2 --max-iter 8 --max-depth 2 --context-window 100000 --output-dir ./results/llama-3.3-70b-instruct
100106
```
101107

102108
Outputs are written to the specified output directory, typically including:
@@ -107,31 +113,11 @@ Outputs are written to the specified output directory, typically including:
107113
### Run only Normal RLM
108114

109115
```bash
110-
python benchmarks/benchmark.py --datasets sniah --methods rlm --n-samples-per-bucket 1 --max-iter 8 --max-depth 2 --context-window 100000 --output-dir ./results_compare
116+
python benchmarks/benchmark.py --datasets sniah --model meta/llama-3.3-70b-instruct --methods rlm --n-samples-per-bucket 2 --max-iter 8 --max-depth 2 --context-window 100000 --output-dir ./results/llama-3.3-70b-instruct_rlm
111117
```
112118

113119
### Run only Lambda-RLM
114120

115121
```bash
116-
python benchmarks/benchmark.py --datasets sniah --methods lambda_rlm --n-samples-per-bucket 1 --max-iter 8 --max-depth 2 --context-window 100000 --output-dir ./results_compare
117-
```
118-
119-
## Repository structure
120-
### Normal RLM
121-
122-
This repository uses upstream Normal RLM components for comparison.
123-
124-
Upstream repository:
125-
`https://github.com/alexzhang13/rlm`
126-
127-
The upstream code is licensed under the MIT License. See `THIRD_PARTY_NOTICES.md` for attribution and licensing details.
128-
129-
Key files:
130-
- `rlm/core/rlm.py` — main REPL-based RLM loop
131-
- `rlm/environments/local_repl.py` — sandboxed Python REPL execution, context storage, and helper functions
132-
- `rlm/utils/parsing.py` — parsing of ```repl``` code blocks and FINAL markers; formatting of execution output back into the model history
133-
- `rlm/clients/openai.py` — OpenAI-compatible client used with NVIDIA NIM
134-
135-
### Lambda-RLM
136-
137-
- `rlm/lambda_rlm.py` — LambdaRLM implementation, including task detection, planning, and deterministic execution through Φ
122+
python benchmarks/benchmark.py --datasets sniah --model meta/llama-3.3-70b-instruct --methods lambda_rlm --n-samples-per-bucket 2 --max-iter 8 --max-depth 2 --context-window 100000 --output-dir ./results/llama-3.3-70b-instruct_lambda_rlm
123+
```

benchmarks/benchmark.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import json
3030
import math
3131
import sys
32-
import os as _os
3332
# Ensure the project root (parent of benchmarks/) is on sys.path so `import rlm` works
3433
# whether the script is run as `python benchmarks/benchmark.py` or `python -m benchmarks.benchmark`.
3534
sys.path.insert(0, str(__import__("pathlib").Path(__file__).resolve().parent.parent))
@@ -55,7 +54,6 @@
5554
import matplotlib
5655
matplotlib.use("Agg")
5756
import matplotlib.pyplot as plt
58-
import matplotlib.ticker as mtick
5957
import numpy as np
6058
_PLOT_AVAILABLE = True
6159
except ImportError:
@@ -86,8 +84,6 @@
8684
#
8785
# Tokens for non-S-Niah datasets are estimated as chars // 4.
8886

89-
import math as _math
90-
9187
BIN_LABELS: list[str] = ["8k", "16k", "32k", "64k", "128k", "256k"]
9288
_BIN_EXPS: list[int] = list(range(13, 19)) # 13..18
9389
_BIN_BOUNDARIES: list[float] = [

intro.png

5.67 MB
Loading

rlm/lambda_rlm.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545

4646
from rlm.clients import BaseLM, get_client
4747
from rlm.core.lm_handler import LMHandler
48-
from rlm.core.types import ClientBackend, EnvironmentType, RLMChatCompletion, UsageSummary
48+
from rlm.core.types import ClientBackend, EnvironmentType, RLMChatCompletion
4949
from rlm.environments.local_repl import LocalREPL
5050
from rlm.logger import RLMLogger
5151

0 commit comments

Comments
 (0)