feat(attention): add KV-BSS (Key-Value Binding Softmax Sharpening) and attention haze suppression

#15
by F-Labs - opened

This PR implements KV-BSS (Key-Value Binding Softmax Sharpening) in modeling_spark.py:

  1. Backwards Compatible: Defaults to key_value_binding_sharpening=False and attention_sink_suppression=False, preserving 100% exact baseline behavior unless explicitly enabled in config.json.
  2. Key-Value Binding Sharpening: When enabled (key_value_binding_sharpening=True), scales attention logits with kv_focus_factor (default 1.10) to steepen peak Softmax probabilities around exact antecedent bindings (e.g. structured JSON, dictionaries, AST variable mapping).
  3. Attention Haze Truncation: Truncates parasitic background attention haze (< max_logits - 12.0) to -inf before Softmax, preventing probability mass diffusion over long sequence windows.

Refer to Community Discussion #14 for empirical derivations and benchmarks:
https://huggingface.co/XHToken/Spark-X2.5-4B/discussions/14
And proof-of-concept release:
https://huggingface.co/F-Labs/Spark-X2.5-4B-Hadamard-GSQ

Ready to merge
This branch is ready to get merged automatically.

Sign up or log in to comment