GFlowPO: Generative Flow Network as a Language Model Prompt Optimizer
Organizations: Korea Advanced Institute of Science and Technology (KAIST) · Korea University · Mila – Québec AI Institute
Abstract
Finding effective prompts for language models (LMs) is critical yet notoriously difficult: the prompt space is combinatorially large, rewards are sparse due to expensive target-LM evaluation. Yet, existing RL-based prompt optimizers often rely on on-policy updates and a meta-prompt sampled from a fixed distribution, leading to poor sample efficiency. We propose GFlowPO, a probabilistic prompt optimization framework that casts prompt search as a posterior inference problem over latent prompts regularized by a meta-prompted reference-LM prior. In the first step, we fine-tune a lightweight prompt-LM with an off-policy Generative Flow Network (GFlowNet) objective, using a replay-based training policy that reuses past prompt evaluations to enable sample-efficient exploration. In the second step, we introduce Dynamic Memory Update (DMU), a training-free mechanism that updates the meta-prompt by injecting both (i) diverse prompts from a replay buffer and (ii) top-performing prompts from a small priority queue, thereby progressively concentrating the search process on high-reward regions. Across few-shot text classification, instruction induction benchmarks, and question answering tasks, GFlowPO consistently outperforms recent discrete prompt optimization baselines.
Figures & tables
| Method | SST-2 | MRPC | RTE | QNLI | MNLI | SNLI | Average | |
|---|---|---|---|---|---|---|---|---|
| Fixed Prompt | Few-Shot Prompt | |||||||
| Manual Prompt | ||||||||
| Discrete Prompt Tuning | APE | |||||||
| ProTeGi | ||||||||
| EvoPrompt | ||||||||
| PromptWizard |
| Instruction Induction (II) | BBII | |||||||||
| Spelling | Syntax | Semantics | Translation | GLUE | Others | All | Text class. | Text gen. | ||
| Method | (4) | (4) | (5) | (4) | (3) | (4) | (24) | (12) | (6) | |
| Fewshot | 3.8 | 0.0 | 0.6 | 0.0 | 35.0 | 0.5 | 5.2 | 51.5 | 6.2 | |
| Manual | 29.6 | 36.8 | 14.6 | 23.3 | 49.7 | 57.1 | 33.7 | 51.6 | 37.6 | |
| APE | 43.8 | 67.2 | 44.5 | 35.9 | 45.9 | 74.7 | 51.9 | 56.5 | 49.6 | |
| ProTeGi | 43.8 | 68.8 | 27.5 | 56.3 | 58.3 | 62.3 | 51.6 | 56.6 | 55.6 | |
| Method | MMLU | OpenBookQA |
|---|---|---|
| APE | 52.1 | 70.7 |
| ProTeGi | 53.5 | 71.5 |
| EvoPrompt | 53.7 | 69.4 |
| PromptWizard | 47.3 | 61.6 |
| GRACE | 47.2 | 70.8 |
| StablePrompt | 55.8 | 72.2 |
| Method | GSM8K | AIME-2025 | BBH (5 randomly chosen tasks) | ||||||
|---|---|---|---|---|---|---|---|---|---|
| movie rec. | object count. | tracking five | hyperbaton | causal | Avg. (5) | All. (19) | |||
| EvoPrompt | |||||||||
| PromptWizard | |||||||||
| GRACE | |||||||||
| StablePrompt | |||||||||
| PRL | |||||||||
| GFlowPO variants | -on-X | -off-X | -on-O | -off-O |
|---|---|---|---|---|
| Avg. Acc. | 74.4 | 75.2 | 78.0 | 80.2 |
Appendix figures & tables20 assets
Supplementary material from the paper’s appendix.
Appendix
| Task | GFlowPO w/o pre-step | GFlowPO - | GFlowPO - | GFlowPO |
|---|---|---|---|---|
| Cause and effect | 80.0 | 76.0 | 52.0 | 88.0 |
| Negation | 83.0 | 89.0 | 86.0 | 87.0 |
| Letters list | 94.0 | 94.0 | 96.0 | 96.0 |
| Larger animal | 56.0 | 91.0 | 90.0 | 93.0 |
| Sentence similarity | 39.0 | 36.0 | 36.0 | 39.0 |
| Num to verbal | 95.0 | 94.0 | 100.0 | 98.0 |
| Hyperparameter | Value |
|---|---|
| Learning rate | |
| Train buffer size | 1000 |
| High-reward buffer size | 5 |
| Total train steps | 200 |
| Pre-steps | 100 |
| Max prompt length | 150 |
| Sentence Similarity | Hyperbaton | |
|---|---|---|
| Manual | Rate from 0 (definitely not) to 5 (perfectly) the degree in which both sentences describe the same event. ( Acc: 20.0 ) | Which sentence has the correct adjective order? ( Acc: 56.5 ) |
| GEPA | You are an AI assistant that applies a transformation to given inputs. Your task is to identify and extract specific details from two sentences and then concatenate them into one sentence, maintaining the same tense and voice. The sentences will always be provided in a pair. The transformation should result in a clear, concise and grammatically correct answer that is logically equivalent to the original sentences … ( Acc: 18.8 ) | The assistant is an AI designed to answer multiple-choice questions by selecting the single best answer. The assistant will be provided with an input and a list of choices, and is expected to output a JSON object with the following format: {"final_answer": <the letter of the correct choice>, "solution_pad": <your reasoning>} . Strictly follow the provided format for outputting your final answer and solution padding … ( Acc: 63.3 ) |
| GFlowPO | I will provide you with two sentences. Based on the given sentences, determine the level of similarity between them. The output should be one of the following numbers: 0 - definitely not 1 - probably not 2 - possibly 3 - probably 4 - almost perfectly Based on the provided input-output pairs, it seems that your friend correctly identified the level of similarity between the two sentences for each pair. ( Acc: 50.0 ) | “Rearrange the adjective and the noun in each input.” based on this instruction, the friend’s output for each input is correct. They have successfully rearranged the order of the adjective and the noun in each input to match the expected output. For example, with the first input: Input: a “gold awful knife” b “awful gold knife” Output: A “awful gold knife” Your friend has correctly rearranged the order of the adjective “awful” and the noun “gold” to match the expected output “awful gold”. Similarly, for the other inputs, the friend has also rearranged the order of the adjective and the noun. ( Acc: 73.0 ) |
| Dataset | Task type | # classes | # training | # test | Verbalizer |
|---|---|---|---|---|---|
| SST2 | Sentiment | 2 | 32 | 872 | [“yes”, “no”] |
| MRPC | NLI | 2 | 32 | 408 | [“yes”, “no”] |
| RTE | NLI | 2 | 32 | 277 | [“yes”, “no”] |
| QNLI | NLI | 2 | 32 | 5,460 | [“yes”, “no”] |
| MNLI | NLI | 3 | 48 | 9,820 | [“yes”, “maybe”, “no”] |
| SNLI | NLI | 3 | 48 | 9,842 | [“yes”, “maybe”, “no”] |
| Task name | Task type | Metric | # training | # test |
|---|---|---|---|---|
| Causal judgment | Multiple choice | Accuracy | 30 | 160 |
| Disambiguation qa | Multiple choice | Accuracy | 30 | 228 |
| Epistemic reasoning | Multiple choice | Accuracy | 30 | 1,970 |
| Hyperbaton | Multiple choice | Accuracy | 30 | 49,970 |
| Implicatures | Multiple choice | Accuracy | 30 | 462 |
| Logical fallacy detection | Multiple choice | Accuracy | 30 | 2,770 |
| Task name | Metric | # training | # test |
|---|---|---|---|
| Antonyms | Exact match | 32 | 100 |
| Word in context | Exact match | 32 | 100 |
| Rhymes | Exact match | 32 | 100 |
| Num to verbal | Exact match | 32 | 100 |
| Cause and effect | Exact match | 26 | 25 |
| Larger animal | Exact match | 32 | 100 |
| Type | Subject | # training | # test |
|---|---|---|---|
| STEM | Abstract algebra | 11 | 100 |
| Anatomy | 14 | 135 | |
| Astronomy | 16 | 152 | |
| College biology | 16 | 144 | |
| College chemistry | 8 | 100 | |
| College computer science | 11 | 100 |
| Task name | Type | Fewshot | Manual | APE | ProTeGi | EvoPrompt | PromptWizard | GRACE | PRL | GEPA | StablePrompt | GFlowPO |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Causal judgment | Multiple choice | 58.8 | 52.5 | 58.1 | 56.7 | |||||||
| Disambiguation qa | Multiple choice | 64.3 | 52.2 | 64.0 | 61.4 | |||||||
| Epistemic reasoning | Multiple choice | 43.7 | 57.2 | 58.4 | 63.8 | |||||||
| Hyperbaton | Multiple choice | 47.9 | 56.5 | 75.6 | 76.1 | |||||||
| Implicatures | Multiple choice | 83.3 | 83.1 | 81.0 | 73.6 | |||||||
| Logical fallacy detection | Multiple choice | 58.2 | 63.5 | 56.5 | 58.2 |
| Task name | Metric | Fewshot | Manual | APE | ProTeGi | EvoPrompt | PromptWizard | GRACE | PRL | GEPA | StablePrompt | GFlowPO |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Antonyms | Exact match | 0.0 | 43.0 | 62.5 | 25.0 | |||||||
| Word in context | Exact match | 55.0 | 46.0 | 37.5 | 50.0 | |||||||
| Rhymes | Exact match | 0.0 | 3.0 | 6.3 | 25.0 | |||||||
| Num to verbal | Exact match | 0.0 | 61.0 | 93.8 | 100.0 | |||||||
| Cause and effect | Exact match | 0.0 | 24.0 | 60.0 | 0.0 | |||||||
| Larger animal | Exact match | 0.0 | 3.0 | 56.3 | 25.0 |
| Task group | Task name | Metric | Fewshot | Manual | APE | ProTeGi | Evo Prompt | Prompt Wizard | GRACE | PRL | GEPA | Stable Prompt | GFlowPO |
| Spelling | First word letter | Exact match | 3.0 | 73.0 | 87.8 | 100.0 | 97.0 | 99.0 | |||||
| Second word letter | Exact match | 12.0 | 8.0 | 6.3 | 25.0 | 9.7 | 27.3 | ||||||
| Letters list | Exact match | 0.0 | 0.0 | 68.8 | 50.0 | 82.3 | 95.3 | ||||||
| Orthography starts with | Exact set | 0.0 | 37.5 | 12.5 | 0.0 | 13.3 | 15.0 | ||||||
| Average | 3.8 | 29.6 | 43.8 | 43.8 | 42.2 | 46.6 | 52.2 | 35.3 | 43.2 | 50.6 | 59.2 | ||
| Syntax | Singular to plural | Exact match | 0.0 | 75.0 | 93.8 | 100.0 | 96.0 | 98.3 |
| Type | Subject | Metric | Fewshot +Manual | CoT | APE | ProTeGi | Evo Prompt | Prompt Wizard | GRACE | PRL | GEPA | Stable Prompt | GFlowPO |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| STEM | Abstract algebra | Accuracy | 30.0 | 33.0 | 31.0 | 35.0 | 31.0 | 30.0 | 32.0 | 29.0 | 38.0 | 33.0 | 31.0 |
| Anatomy | Accuracy | 50.4 | 51.9 | 49.6 | 53.0 | 54.1 | 55.6 | 48.2 | 56.3 | 54.8 | 53.3 | 52.6 | |
| Astronomy | Accuracy | 57.9 | 64.5 | 54.0 | 56.6 | 61.2 | 57.9 | 52.6 | 58.6 | 57.2 | 63.2 | 57.9 | |
| College biology | Accuracy | 66.7 | 67.4 | 57.0 | 65.8 | 55.0 | 46.0 | 45.0 | 60.4 | 68.1 | 65.3 | 56.9 | |
| College chemistry | Accuracy | 38.0 | 34.0 | 39.0 | 40.0 | 60.4 | 46.4 | 45.3 | 32.0 | 35.0 | 39.0 | 36.0 | |
| College computer science | Accuracy | 41.0 | 48.0 | 32.8 | 37.0 | 60.4 | 56.3 | 59.0 | 41.0 | 45.0 | 40.0 | 39.0 |
| Method | w/o DMU | w/ DMU |
|---|---|---|
| Frozen Prompt-LM | 69.9 | 74.4 |
| Reward-weighted off-policy MLE | 73.3 | 74.4 |
| On-policy GFlowNet | 74.4 | 78.0 |
| Off-policy GFlowNet | 75.2 | 80.2 |
| Method | Zero shot | Few shot | Manual | Stable Prompt | GEPA | GFlowPO |
|---|---|---|---|---|---|---|
| Avg. (6 tasks) | 71.2 | 71.5 | 71.2 |
| Disambiguation QA | Geometric Shapes | Movie Recommendation | |
|---|---|---|---|
| Manual | Identify what the pronoun refers to. Weigh each possible antecedent against the sentence; if the reference is genuinely ambiguous, say so rather than forcing a choice. ( Acc: 64.0 ) | Treat the SVG path as a figure defined by vertices and line segments. Trace the path, count the distinct vertices and edges, and identify the shape. ( Acc: 65.0 ) | Recall the genre, tone, era, and reception of the listed movies. Compare each option against these shared traits and pick the most similar one. ( Acc: 80.0 ) |
| GFlowPO | For each sentence, identify the antecedent of the pronoun (which noun phrase it refers to) and select the correct option. The pronoun refers to the subject of the sentence unless context clearly indicates otherwise. If the antecedent is ambiguous or unclear, choose (C) Ambiguous. Provide only the letter (A, B, or C) as the output. ( Acc: 67.0 ) | Identify the geometric shape described by the SVG path element. Count the number of distinct vertices connected by line segments to determine the shape. If the shape has 6 vertices, output ‘C’ for hexagon. If it has 8 vertices, output ‘F’ for octagon. If it contains an arc and is not a polygon, output ‘K’ for ellipse. If it has 5 vertices, output ‘G’ for pentagon. If it contains an arc and forms a sector, output ‘I’. If it contains an arc and forms a kite, output ‘D’. If it contains an arc and forms a circle, output ‘A’. If it has 7 vertices, output ‘B’ for heptagon. If it … ( Acc: 88.0 ) | Select the movie from the options that is most similar in theme, genre, or narrative to the listed films, with a focus on critical acclaim and shared storytelling elements. Output the letter corresponding to the most appropriate choice. ( Acc: 88.0 ) |
| Sentence Similarity | Hyperbaton | |
|---|---|---|
| Manual | Rate from 0 (definitely not) to 5 (perfectly) the degree in which both sentences describe the same event. ( Acc: 20.0 ) | Which sentence has the correct adjective order? ( Acc: 56.5 ) |
| GFlowPO | I will provide you with two sentences. Based on the given sentences, determine the level of similarity between them. The output should be one of the following numbers: 0 - definitely not 1 - probably not 2 - possibly 3 - probably 4 - almost perfectly Based on the provided input-output pairs, it seems that your friend correctly identified the level of similarity between the two sentences for each pair. ( Acc: 50.0 ) | “Rearrange the adjective and the noun in each input.” based on this instruction, the friend’s output for each input is correct. They have successfully rearranged the order of the adjective and the noun in each input to match the expected output. For example, with the first input: Input: a “gold awful knife” b “awful gold knife” Output: A “awful gold knife” Your friend has correctly rearranged the order of the adjective “awful” and the noun “gold” to match the expected output “awful gold”. Similarly, for the other inputs, the friend has also rearranged the order of the adjective and the noun. ( Acc: 73.0 ) |
| 2 | 3 | 4 | 5 | |
|---|---|---|---|---|
| (1, 1) | (2, 1) | (2, 2) | (3, 2) | |
| Avg. accuracy | 77.6 | 80.2 | 78.9 | 79.2 |