# US 2025/0148276 A1 · All-shot training of large language models

> Agents: this data is available as JSON from the patentgrep API and MCP server — see https://patentgrep.com/llms.txt

- Number: US 2025/0148276 A1
- Document ID: US20250148276A1
- Status: Published application
- Kind: A1
- Application number: 18/387,152
- Filed: 2023-11-06
- Published: 2025-05-08
- Earliest claimed: 2023-11-06
- Assignees: SambaNova Systems, Inc.
- Applicants: SambaNova Systems, Inc.
- Inventors: Zoltan Csaki; Bo Li; Urmish Ajit Thakker; Venkat Krishna SRINIVASAN
- Web page: https://patentgrep.com/patent/US20250148276A1

## CPC

- G06N 3/08: Learning methods
- G06N 3/084: Backpropagation, e.g. using gradient descent
- G06F 16/53: Querying
- G06N: COMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
- G06F: ELECTRIC DIGITAL DATA PROCESSING (computer systems based on specific computational models G06N)

## Abstract

Embodiments described herein provide systems and techniques for training large language models. In one aspect, a process for performing in-context training of a language model is disclosed. This process may begin by receiving a language model that includes a context window of a predetermined size, as well as receiving a set of in-context prompt/completion pairs prepared for a target task. The process then constructs a first token sequence based on the set of in-context prompt/completion pairs. Next, the process fits the first token sequence into the context window. The process subsequently performs a first in-context training pass using the first token sequence to train the language model to generate a next token in accordance with the target task.

## Claims

### Claim 1

A method of performing in-context training for a machine learning (ML) model, comprising:
receiving an ML model comprising a context window of a predetermined size;
receiving a set of in-context prompt/completion pairs prepared for a target task;
constructing a first token sequence based on the set of in-context prompt/completion pairs;
fitting the first token sequence into the context window; and
performing a first in-context training pass using the first token sequence to train the ML model to generate a next token in accordance with the target task.

### Claim 2 (depends on 1)

The method of claim 1, wherein constructing the first token sequence based on the set of in-context prompt/completion pairs includes:
selecting a first subset of the set of in-context prompt/completion pairs, wherein the combined size of the selected first subset of the in-context prompt/completion pairs is less than or equal to the predetermined size of the context window; and
concatenating the selected first subset of the in-context prompt/completion pairs to form the first token sequence.

### Claim 3 (depends on 2)

The method of claim 2, wherein the first subset of the in-context prompt/completion pairs is selected such that the combined size of the selected first subset of the in-context prompt/completion pairs is as close to the predetermined size as possible without exceeding the predetermined size to maximize the usage of the context window and to include as many different prompt/completion pairs as possible.

### Claim 4 (depends on 2)

The method of claim 2, wherein after completing the first in-context training pass using the first token sequence, the method further comprises:
determining if there are unselected prompt/completion pairs in the set of in-context prompt/completion pairs by the first in-context training; and
in response to determining that there are unselected prompt/completion pairs,
constructing a second token sequence based on the set of in-context prompt/completion pairs;
fitting the second token sequence into the context window; and
performing a second in-context training pass using the second token sequence to further train the ML model to perform the target task.

### Claim 5 (depends on 4)

The method of claim 4, wherein constructing the second token sequence based on the set of in-context prompt/completion pairs includes:
selecting a second subset of the set of in-context prompt/completion pairs, wherein:
the second subset of in-context prompt/completion pairs does not include any in-context prompt/completion pair in the first subset of in-context prompt/completion pairs; and
the combined size of the selected second subset of the in-context prompt/completion pairs is as close to the predetermined size as possible to maximize the usage of the context window and to include as many different and unused prompt/completion pairs as possible; and
concatenating the selected second subset of the in-context prompt/completion pairs to form the second token sequence.

### Claim 6 (depends on 4)

The method of claim 4, wherein after completing the second in-context training pass using the second token sequence, the method further comprises:
determining if there are unselected prompt/completion pairs in the set of in-context prompt/completion pairs from the first in-context training pass and the second in-context training pass; and
in response to determining that there are unselected prompt/completion pairs,
constructing a third token sequence from the unselected prompt/completion pairs;
fitting the third token sequence into the context window; and
performing a third in-context training pass using the third token sequence to further train the ML model to perform the target task.

### Claim 7 (depends on 6)

The method of claim 6, wherein the method further comprises:
determining if there are unselected prompt/completion pairs in the set of in-context prompt/completion pairs from all of the previous in-context training passes; and
if so,
constructing one or more additional token sequences from the unselected prompt/completion pairs until the set of in-context prompt/completion pairs are fully exhausted; and
performing one or more additional in-context training passes using the one or more additional token sequences to further train the ML model;
otherwise,
terminating the in-context training for the ML model,
wherein there is no duplicated prompt/completion pair used by any two in-context training passes in the set of in-context training passes,
thereby improving a model training efficiency based on the set of in-context prompt/completion pairs.

### Claim 8 (depends on 7)

The method of claim 7, wherein a training time associated with training the ML model is proportional to a first number of in-context prompt/completion pairs in the set of in-context prompt/completion pairs divided by an average number of selected prompt/completion pairs of a set of constructed token sequences associated with the set of in-context training passes.

### Claim 9 (depends on 1)

The method of claim 1, wherein performing the first in-context training pass using the first token sequence includes:
initially using the first prompt/completion pair in the first token sequence to perform a zero-shot training without involving other prompt/completion pairs in the first token sequence; and
backpropagating from the second prompt/completion pair that immediately follows the first prompt/completion pair while using the first prompt/completion pair as an associated context, thereby effectively performing a one-shot training on the second prompt/completion pair.

### Claim 10 (depends on 9)

The method of claim 9, wherein after performing the one-shot training, the method further comprises:
determining if there is at least a third prompt/completion pair following the second prompt/completion pair in the first token sequence; and
if so,
backpropagating from the third prompt/completion pair immediately following the second prompt/completion pair while using the first and second prompt/completion pairs as the associated context, thereby effectively performing a two-shot training on the third prompt/completion pair;
otherwise,
terminating the first in-context training pass based on the first token sequence.

### Claim 11 (depends on 10)

The method of claim 10, wherein after performing the two-shot training, the method further comprises:
determining if there is at least a fourth prompt/completion pair following the third prompt/completion pair in the first token sequence; and
if so,
backpropagating from the fourth prompt/completion pair immediately following the third prompt/completion pair while using the first, second, and third prompt/completion pairs as the associated context, thereby effectively performing a three-shot training on the fourth prompt/completion pair;
otherwise,
terminating the first in-context training pass based on the first token sequence.

### Claim 12 (depends on 1)

The method of claim 1, wherein the first token sequence is composed of a sequence of N concatenated prompt/completion pairs, and wherein performing the first in-context training pass using the first token sequence includes:
performing a zero-shot training by backpropagating on the first completion token in the first prompt/completion pair without involving other prompt/completion pairs in the first token sequence; and
sequentially performing N−1 backward passes, wherein each backward pass in the sequence of N−1 backward passes is a (M−1)-shot training on the Mth completion token the Mth prompt/completion pair in the first token sequence while using the preceding M−1 prompt/completion pairs as context, wherein M=2, . . . , N.

### Claim 13 (depends on 1)

The method of claim 1,
wherein the ML model includes a transformer model; and
wherein performing the first in-context training pass using the first token sequence includes training the transformer model using the first token sequence.

### Claim 14 (depends on 1)

The method of claim 1, wherein the target task is to respond to queries of a target topic, and wherein the set of in-context prompt/completion pairs is a set of query/answer examples of the same target topic.

### Claim 15 (depends on 1)

The method of claim 1, wherein each prompt/completion pair in the set of in-context prompt/completion pairs has the same format as the other prompt/completion pairs in the set of in-context prompt/completion pairs.

### Claim 16

An apparatus for performing in-context training for a machine learning (ML) model, the apparatus comprising:
one or more processors;
a memory coupled to the one or more processors, the memory storing instructions that, when executed by the one or more processors, cause the apparatus to;
receive an ML model comprising a context window of a predetermined size;
receive a set of in-context prompt/completion pairs prepared for a target task;
construct a set of token sequences based on the set of in-context prompt/completion pairs, wherein each token sequence in the set of token sequences can be fitted into the context window; and
perform a sequence of in-context training passes using the set of token sequences to train the ML model to generate a next token in accordance with the target task.

### Claim 17 (depends on 16)

The apparatus of claim 16, wherein the set of token sequences includes a first token sequence, and wherein the memory further stores instructions that, when executed by the one or more processors, cause the apparatus to construct the first token sequence by:
selecting a first subset of the set of in-context prompt/completion pairs, wherein the combined size of the selected first subset of the in-context prompt/completion pairs is equal to or substantially equal to the predetermined size of the context window; and
concatenating the selected first subset of the in-context prompt/completion pairs to form the first token sequence,
wherein the first token sequence is used to perform a first in-context training pass in the sequence of in-context training passes.

### Claim 18 (depends on 17)

The apparatus of claim 17, wherein the first subset of the in-context prompt/completion pairs is selected such that the combined size of the selected first subset of the in-context prompt/completion pairs is as close to the predetermined size as possible without exceeding the predetermined size to maximize the usage of the context window and to include as many different prompt/completion pairs as possible.

### Claim 19 (depends on 17)

The apparatus of claim 17, wherein after constructing the first token sequence, the memory further stores instructions that, when executed by the one or more processors, cause the apparatus to:
determine if there are unselected prompt/completion pairs in the set of in-context prompt/completion pairs by the first in-context training pass; and
in response to determining that there are unselected prompt/completion pairs,
select a second subset of the set of in-context prompt/completion pairs, wherein the combined size of the selected second subset of the in-context prompt/completion pairs is equal to or substantially equal to the predetermined size of the context window; and
concatenate the selected second subset of the in-context prompt/completion pairs to form the second token sequence,
wherein the second token sequence is used to perform a second in-context training pass in the sequence of in-context training passes.

### Claim 20 (depends on 17)

The apparatus of claim 17, wherein the first token sequence is composed of a sequence of N concatenated prompt/completion pairs, and wherein the memory further stores instructions that, when executed by the one or more processors, cause the apparatus to perform the first in-context training pass by:
performing a zero-shot training by backpropagating on the first completion token in the first prompt/completion pair without involving other prompt/completion pairs in the first token sequence; and
sequentially performing N−1 backward passes, wherein each backward pass in the sequence of N−1 backward passes is a (M−1)-shot training on the Mth completion token in the Mth prompt/completion pair in the first token sequence while using the preceding M−1 prompt/completion pairs as context, wherein M=2, . . . , N.

### Claim 21 (depends on 17)

The apparatus of claim 17, wherein a training time associated with training the ML model is proportional to a first number of in-context prompt/completion pairs in the set of in-context prompt/completion pairs divided by an average number of selected prompt/completion pairs associated with the set of token sequences.

### Claim 22

A system for performing in-context training for a machine learning (ML) model, the system comprising:
one or more processors;
a memory coupled to the one or more processors, the memory storing instructions that, when executed by the one or more processors, cause the system to:
receive an ML model comprising a context window of a predetermined size;
receive a set of in-context prompt/completion pairs prepared for a target task;
construct a first token sequence based on the set of in-context prompt/completion pairs;
fit the first token sequence into the context window; and
perform a first in-context training pass using the first token sequence to train the ML model to generate a next token in accordance with the target task.

### Claim 23 (depends on 22)

The system of claim 22,
wherein the ML model includes a transformer-based language model; and
wherein performing the first in-context training pass using the first token sequence includes training the transformer-based language model.
