The invention discloses a large
language model reasoning acceleration method and device based on two-stage speculative decoding and a storage medium, and the method comprises the steps: constructing and initializing a
Trie tree, and inserting a historical corpus, and
phrase sequences in a document
library or a code
library into the
Trie tree one by one; in the reasoning process, longest prefix matching is carried out based on a
Trie tree, and a candidate draft sequence is generated by adopting
branch backtracking and recursive search; performing confidence evaluation on the candidate draft sequence, calculating a joint
confidence score of the sequence through probability multiplication and a Top-K screening mechanism, and judging whether the joint
confidence score reaches a
confidence threshold; if the accumulated confidence of the candidate sequence reaches a threshold value, skipping a small model generation stage, and directly entering
large model verification; otherwise, entering a small model draft completion stage; and the final
large model takes the replaced and updated draft sequence as final output. According to the method, adaptive acceleration of the decoding process can be realized, and the long text reasoning
delay of the large
language model is remarkably reduced while the generation quality is ensured.