From 07163fb627f5a43d48b9698bdeb1322279c3a379 Mon Sep 17 00:00:00 2001 From: ochafik Date: Mon, 8 Apr 2024 20:10:15 +0100 Subject: [PATCH] grammars: add troubleshooting section to readme --- grammars/README.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/grammars/README.md b/grammars/README.md index e1383fa5c..5c210de4c 100644 --- a/grammars/README.md +++ b/grammars/README.md @@ -89,3 +89,13 @@ This guide provides a brief overview. Check out the GBNF files in this directory ``` ./main -m --grammar-file grammars/some-grammar.gbnf -p 'Some prompt' ``` + +## Troubleshooting + +Grammars currently have performance gotchas (see https://github.com/ggerganov/llama.cpp/issues/4218). + +### Efficient optional repetitions + +A common pattern is to allow repetitions of a pattern `x` up to N times. + +While semantically correct, the syntax `x? x? x?.... x?` (with N repetitions) will result in extremely slow inference. Instead, you can write `(x (x (x ... (x)?...)?)?)?` (w/ N-deep nesting) \ No newline at end of file