# US 2025/0148205 A1 · Combining in-context learning and instruction tuning to enhance 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/0148205 A1
- Document ID: US20250148205A1
- Status: Published application
- Kind: A1
- Application number: 18/387,445
- 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/US20250148205A1

## CPC

- G06F 40/284: Lexical analysis, e.g. tokenisation or collocates
- 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 few-shot training for a transformer-based language model is disclosed. This process may begin by receiving the transformer-based language model having a context window of a predetermined size, as well as a training dataset comprising a set of prompt/completion examples. The process then constructs a training sequence based on the training dataset. Next, the process performs a single forward pass using the training sequence as input. The process subsequently performs a set of backward passes from a subset of examples in the training sequence, wherein each backward pass is conditioned on a selected subset of prompt/completion examples in the training sequence. Performing multiple backward passes conditioned on selected prompt/completion examples improves the language model's ability to generate a higher quality conditional probability distribution for next token without incurring additional training time.

## Claims

### Claim 1

A method of performing in-context few-shot training for a transformer-based language model, comprising:
receiving the transformer-based language model having a context window of a predetermined size;
receiving a training dataset comprising a set of K prompt/completion examples;
constructing a first training sequence based on the training dataset;
performing a single forward pass using the first training sequence as input; and
performing a set of backward passes from a subset of examples in the first training sequence, wherein each backward pass is conditioned on a selected subset of prompt/completion examples in the first training sequence,
wherein performing multiple backward passes conditioned on the selected prompt/completion examples in the first training sequence improves the language model's ability to generate a higher quality conditional probability distribution for a next token without incurring additional training time.

### Claim 2 (depends on 1)

The method of claim 1, wherein constructing the first training sequence based on the training dataset includes:
selecting from the set of K prompt/completion examples, a set of N prompt/completion examples, wherein N≤K and the combined size of the selected N prompt/completion examples is equal to or less than the predetermined size of the context window; and
concatenating the selected set of N prompt/completion examples to form the first training sequence.

### Claim 3 (depends on 1)

The method of claim 1, wherein performing the single forward pass using the first training sequence includes:
calling the transformer-based language model; and
passing the first training sequence through the transformer-based language model to generate a next token prediction based on the first training sequence.

### Claim 4 (depends on 2)

The method of claim 2, wherein while performing the single forward pass, the method further comprises:
specifying a set of loss masks within the training sequence for the set of backward passes, wherein each loss mask in the set of loss masks is a unique example in the set of N prompt/completion examples to begin a backward pass; and
specifying a set of attention masks for the set of loss masks, wherein each attention mask in the set of attention masks specifies, during a backward pass from a corresponding loss mask, a subset of prompt/completion examples within the training sequence for the backward pass to be conditioned on.

### Claim 5 (depends on 4)

The method of claim 4,
wherein each loss mask in the set of loss masks is one of the N completions in the set of N prompt/completion examples; and
wherein the set of loss masks is composed of a subset of the N completions in the set of N prompt/completion examples.

### Claim 6 (depends on 4)

The method of claim 4, wherein the set of loss masks is composed of the set N completions in the set of N prompt/completion examples.

### Claim 7 (depends on 4)

The method of claim 4, wherein a specified attention mask for a corresponding loss mask includes each and every prompt/completion example in the first training sequence preceding the corresponding loss mask.

### Claim 8 (depends on 4)

The method of claim 4, wherein a specified attention mask for a corresponding loss mask includes both a first subset of prompt/completion examples in the first training sequence preceding the corresponding loss mask and a second subset of prompt/completion examples in the first training sequence succeeding the corresponding loss mask.

### Claim 9 (depends on 4)

The method of claim 4, wherein performing a backward pass in the set of backward passes includes performing a backpropagation from a corresponding loss mask conditioned on each and every prompt/completion example in the first training sequence preceding the corresponding loss mask, thereby effectively performing a few-shot training on the corresponding loss mask.

### Claim 10 (depends on 4)

The method of claim 4, wherein the set of backward passes includes N backward passes, and wherein each of the N backward passes includes performing a backpropagation from each of the N completions in the set of N prompt/completion examples conditioned on each and every prompt/completion example in the first training sequence preceding the corresponding completion, thereby performing multiple different few-shot trainings on the set of loss masks.

### Claim 11 (depends on 1)

The method of claim 1, wherein after performing the set of backward passes using the first training sequence, the method further comprises:
determining if there are unselected prompt/completion examples in the training dataset after constructing the first training sequence; and
in response to determining that there are unselected prompt/completion examples,
constructing a second training sequence from the unselected prompt/completion examples in the set of K prompt/completion examples; and
performing a second training pass based the second training sequence.

### Claim 12 (depends on 11)

The method of claim 11, wherein performing the second training pass includes:
performing a single forward pass using the second training sequence as input; and
performing a set of backward passes from a subset of examples in the second training sequence, wherein each backward pass is conditioned on a selected subset of prompt/completion examples in the second training sequence.

### Claim 13 (depends on 1)

The method of claim 1, wherein a total training time for the transformer-based language model based on the training dataset is proportional to a number of forward passes, which is determined by a number of unique training sequences constructed from the training dataset.

### Claim 14 (depends on 13)

The method of claim 13, wherein the method further comprises reducing the total training time by reducing the number of unique training sequences, wherein reducing the number of unique training sequences includes maximizing the usage of the context window.

### Claim 15

An apparatus for performing in-context few-shot training for a transformer-based language 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 the transformer-based language model having a context window of a predetermined size;
receive a training dataset comprising a set of K prompt/completion examples;
construct a first training sequence based on the training dataset;
perform a single forward pass using the first training sequence as input; and
perform a set of backward passes from a subset of examples in the first training sequence, wherein each backward pass is conditioned on a selected subset of prompt/completion examples in the first training sequence,
wherein performing multiple backward passes conditioned on the selected prompt/completion examples in the first training sequence improves the language model's ability to generate a higher quality conditional probability distribution for a next token without incurring additional training time.

### Claim 16 (depends on 15)

The apparatus of claim 15, wherein the memory further stores instructions that, when executed by the one or more processors, cause the apparatus to construct the first training sequence by:
selecting from the set of K prompt/completion examples, a set of N prompt/completion examples, wherein N≤K and the combined size of the selected N prompt/completion examples is equal to or less than the predetermined size of the context window; and
concatenating the selected set of N prompt/completion examples to form the first training sequence.

### Claim 17 (depends on 15)

The apparatus of claim 15, wherein the memory further stores instructions that, when executed by the one or more processors, cause the apparatus to perform the single forward pass by:
calling the transformer-based language model; and
passing the first training sequence through the transformer-based language model to generate a next token prediction based on the first training sequence.

### Claim 18 (depends on 17)

The apparatus of claim 17, wherein while performing the single forward pass, the memory further stores instructions that, when executed by the one or more processors, cause the apparatus to:
specify a set of loss masks within the first training sequence for the set of backward passes, wherein each loss mask in the set of loss masks is a unique example in the set of N prompt/completion examples to begin a backward pass; and
specify a set of attention masks for the set of loss masks, wherein each attention mask in the set of attention masks specifies, during a backward pass from a corresponding loss mask, a subset of prompt/completion examples within the first training sequence for the backward pass to be conditioned on.

### Claim 19 (depends on 18)

The apparatus of claim 18, wherein the memory further stores instructions that, when executed by the one or more processors, cause the apparatus to perform a backward pass in the set of backward passes by performing a backpropagation from a corresponding loss mask conditioned on each and every prompt/completion example in the first training sequence preceding the corresponding loss mask, thereby effectively performing a few-shot training on the corresponding loss mask.

### Claim 20 (depends on 18)

The apparatus of claim 18, wherein the set of backward passes includes N backward passes, and wherein each of the N backward passes includes performing a backpropagation from of each of the N completions in the set of N prompt/completion examples conditioned on each and every prompt/completion example in the first training sequence preceding the corresponding completion, thereby performing multiple different few-shot trainings on the set of loss masks.

### Claim 21

A system for performing in-context few-shot training for a transformer-based language 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 the transformer-based language model having a context window of a predetermined size;
receive a training dataset comprising a set of K prompt/completion examples;
construct a first training sequence based on the training dataset;
perform a single forward pass using the first training sequence as input; and
perform a set of backward passes from a subset of examples in the first training sequence, wherein each backward pass is conditioned on a selected subset of prompt/completion examples in the first training sequence,
wherein performing multiple backward passes conditioned on the selected prompt/completion examples in the first training sequence improves the language model's ability to generate a higher quality conditional probability distribution for a next token without incurring additional training time.

### Claim 22 (depends on 21)

The system of claim 21, wherein a total training time for the transformer-based language model based on the training dataset is proportional to a number of forward passes, which is determined by a number of unique training sequences constructed from the training dataset.

### Claim 23 (depends on 22)

The system of claim 22, wherein the total training time is reduced by reducing the number of unique training sequences, which involves maximizing the usage of the context window.
