From 6037242f57f5caafedd93ea94eaf41aed22a8ac0 Mon Sep 17 00:00:00 2001 From: Hudson Cooper Date: Fri, 31 May 2024 18:06:27 -0700 Subject: [PATCH] First pass at a fix for #863 --- guidance/_parser.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/guidance/_parser.py b/guidance/_parser.py index 600d0cb43..8ae37fb75 100644 --- a/guidance/_parser.py +++ b/guidance/_parser.py @@ -594,10 +594,13 @@ def _record_captures_from_root(self, initial_item, data, log_prob_data): def _compute_parse_tree(self, initial_pos, initial_item, reversed_state_sets): stack = [(initial_pos, initial_item)] + seen = set() while stack: pos, item = stack.pop() - + if (pos, item) in seen: + # Skip items we have already processed + continue # compute the children for this item assert self._compute_children(pos, item, reversed_state_sets)