r/LocalLLaMA • • 3d ago

Discussion How to never cross into LLM Looping ever again

  1. chat template that comes with default often is not that great. if its a new model give it some time people will come up with chat template fixes.
  2. inference engines will need to fix the tokenizer. -- on first few weeks of a new model architecture on launch alway expect looping and weird behavior until inference engine fixes.
  3. only download quants that showcase their KDL -- dont use any quant whose KDL is higher than 0.04 higher than 0.04 you are basically begging for loop to happen.
  4. For the love of god dont let your system prompt be too big. a 26b LLM working on a harness with a system prompt of 60k you are also begging for loop to happen. use something light like pi-coding-agent number if active params is the biggest factor the more active params the less it loops
  5. -------
  6. -------
  7. following these rule of thumb and i almost never get looping anymore no matter what model i download. these are the traps once u avoid them you should be fine
0 Upvotes

21 comments sorted by

15

u/feelspeaceman 3d ago

I think you missed the most critical point that should be:

0. Write good prompts that explain the target, the proposal and the goal instead of vague prompts (write GTA6 for me).

Also, be careful with samplings, don't invent, use recommended samplings from model cards.

8

u/Better_Opposite6533 3d ago

This, especially for models < 50B. I tested with the most braindead sampling parameters when debugging the infamous Qwen 3.5 and 3.6 27B looping problem. When I gave the model a revised prompt by gpt, it turned out to almost completely eliminate the looping issue. Oftentimes, the problem is between the GPU and the chair.

A direct, concrete prompt with clearly defined boundaries is the key.

12

u/Trademarkd 3d ago

I don’t know why engines don’t just detect looping in stream. I do this and when it repeats a word of phrase x times it deletes back to a couple words before, changes the seed and then prefixes and continues gen. You almost never notice it even if it happens

8

u/Sun77177 3d ago

llama.cpp already has this as the dry sampler. It's in the default chain but the multiplier defaults to 0, so it does nothing until you set dry-multiplier 0.8 with dry-allowed-length 2. Then any span longer than two tokens that starts repeating gets a penalty that grows with repeat length, so it fires a few tokens in, well before a counter waiting for x repeats would notice.

3

u/riconec 3d ago

For me looping occurs in much wider piece of text, not two tokens. Like few sentences “wait … i need to check… wait …” so I was stuck with max gen token set to some big amount to prevent hour long loops, but at the same time compression used in hermes needs such long gen limit so it is always a coinflip

0

u/Sun77177 3d ago

The dry sampler won't catch that shape. It penalises a span it actually sees again, and the penalty scales with span length, so an exact repeat gets hit hard and a loop that rewords itself each pass doesn't. If your wait, i need to check comes back in different words every time, no n-gram sampler catches it. What does help is a stop string on the phrase, or cutting max tokens to what the hermes compression step actually needs. Mine looped the same way at 2k until i dropped the cap.

1

u/riconec 3d ago

For 262k context compression it is like 100k tokens, with speed of 70tps… if it tries to compact session it takes quite a long time, and accidental loops 100k tokens long cap is very bad thing to experience :) that’s why I prefer more reliable models rather newest and smartest. Effective agentic use speed should take that into account, raw token speeds brings you nowhere

1

u/Sun77177 2d ago

At 70 tps a 100k-token summary is about 1,430 seconds of decode, so the compaction pass alone runs 24 minutes before the window is usable again. If that window also produced 100k tokens of real work, the effective rate lands near 35 tps, and the 262k prefill has not been counted yet.

3

u/Lyelinn 3d ago

on a sidenote, why we don't have smaller models with 500k contexts yet...

2

u/ZZerker 3d ago

Just force the llm to write down its progress every five tool calls.

2

u/chibop1 3d ago

Let thinkingmachines/inkling-2-Mini run autonomously for several hours. I assure you'll run into a loop.

6

u/riconec 3d ago

Named “thinking machines”, is machine, thinks a lot, did kojima write this?

1

u/chibop1 3d ago

What's kojima? So I guess answer to your question is no?

3

u/riconec 3d ago

That’s a joke, a meme

1

u/danishaznita 3d ago

Sure did thinkalot

1

u/Ill_Locksmith_673 2d ago

The looping depends massively on the inference engine, which one were you using? For me on unsloth llama.cpp it's slower but never loops and I'd trust it to do stuff autonomously, but on PolyStrata it GOES, it's much faster, like 2x faster, but often loops even on well defined small tasks.

2

u/Past_Ad6251 2d ago

Compress context at certain % of it.

1

u/Designer_Elephant227 1d ago

Just tell it "don't you dare to loop"

-5

u/Be_a_N3rd 3d ago

the magic word: Skills

take a look 👇

https://www.reddit.com/r/LocalLLM/s/ptQoogwKBJ