Views
No views yet
We observe that the majority of logits follow a Gaussian distribution in the lower-value region, which corresponds to the low-probability tails that are commonly treated as noise in the probability distribution. This pattern suggests the potential for more meaningful truncation in the logit space.
Qwen/Qwen2.5-0.5B-Instructtransformer LLM/VLM trained for causal language modeling.n_sigma to the generation function.n_sigma number of standard deviations below the max logit score.n_sigma=1.0 for most use cases, but you can experiment with values in the range (0.0, 2√3].1from transformers import AutoModelForCausalLM, AutoTokenizer
2from transformers import GenerationConfig
3
4tokenizer = AutoTokenizer.from_pretrained("Qwen/Qwen3-0.6B")
5model = AutoModelForCausalLM.from_pretrained("Qwen/Qwen3-0.6B", device_map="auto")
6generation_config = GenerationConfig(temperature=1.5, max_length=128)
7
8messages = [{"role":"user", "content": "Write a story about a dog and cat becoming friends."}]
9text = tokenizer.apply_chat_template(
10 messages,
11 tokenize=False,
12 add_generation_prompt=True,
13 enable_thinking=False # Switches between thinking and non-thinking modes. Default is True.
14)
15model_inputs = tokenizer([text], return_tensors="pt").to(model.device)
16# There is a print message hardcoded in the custom generation method
17gen_out = model.generate(**model_inputs, n_sigma=1.0, generation_config=generation_config, custom_generate="Pramodith/topN_sigma_generation", trust_remote_code=True)
18
19print(tokenizer.batch_decode(gen_out, skip_special_tokens=True)[0])1@inproceedings{tang2025top,
2 title={Top-n𝜎: Eliminating Noise in Logit Space for Robust Token Sampling of LLM},
3 author={Tang, Chenxia and Liu, Jianchun and Xu, Hongli and Huang, Liusheng},
4 booktitle={Proceedings of the 63rd Annual Meeting of the Association for Computational Linguistics (Volume 1: Long Papers)},
5 pages={10758--10774},
6 year={2025}
7}