From f17e434d512afa502975b62c9f07777e8bd7ba0f 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 | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/guidance/_parser.py b/guidance/_parser.py index 600d0cb43..331f2210e 100644 --- a/guidance/_parser.py +++ b/guidance/_parser.py @@ -594,10 +594,14 @@ 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 + seen.add((pos, item)) # compute the children for this item assert self._compute_children(pos, item, reversed_state_sets)