Feature Extraction
Transformers
Safetensors
lemondecider_decision
decision-model
typed-decisions
multimodal
custom_code
Instructions to use inclusionAI/LemonDecider with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use inclusionAI/LemonDecider with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("feature-extraction", model="inclusionAI/LemonDecider", trust_remote_code=True)# pip install -U transformers accelerate # Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("inclusionAI/LemonDecider", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
Update configuration_lemondecider.py
Browse files
configuration_lemondecider.py
CHANGED
|
@@ -1,8 +1,10 @@
|
|
| 1 |
-
|
|
|
|
| 2 |
import math
|
| 3 |
from transformers.configuration_utils import PreTrainedConfig
|
| 4 |
from transformers.models.llama.configuration_llama import LlamaConfig
|
| 5 |
from transformers.models.qwen3_5.configuration_qwen3_5 import Qwen3_5Config
|
|
|
|
| 6 |
|
| 7 |
|
| 8 |
_LLAMA_KEYS = {
|
|
@@ -82,8 +84,9 @@ class LemonDeciderConfig(Qwen3_5Config):
|
|
| 82 |
def __init__(self, codes=None, token_ids=None, max_options=255, temperature=1.0,
|
| 83 |
base_model="Qwen/Qwen3.8-27B", initialization_step=0,
|
| 84 |
max_input_length=8192, code_scheme="letters-v1",
|
| 85 |
-
backbone_type=None, llama_config=None,
|
| 86 |
-
attention_mode="causal", pooling="last", decision_protocol="
|
|
|
|
| 87 |
# auto_map is the serialized trust_remote_code contract of every published
|
| 88 |
# checkpoint: the serving/eval stack reloads exported configs via AutoModel.
|
| 89 |
# Stash instead of dropping it, then re-attach after the base constructors
|
|
@@ -96,7 +99,17 @@ class LemonDeciderConfig(Qwen3_5Config):
|
|
| 96 |
if "torch_dtype" in kwargs and "dtype" not in kwargs:
|
| 97 |
kwargs["dtype"] = kwargs.pop("torch_dtype")
|
| 98 |
llama_mode = _llama_requested(backbone_type, llama_config, kwargs)
|
| 99 |
-
if
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 100 |
if attention_mode != "causal":
|
| 101 |
raise ValueError("noncausal_full_attention is only implemented for the Qwen3.5 hybrid backbone")
|
| 102 |
inner = _llama_from_kwargs(llama_config, kwargs)
|
|
@@ -118,12 +131,27 @@ class LemonDeciderConfig(Qwen3_5Config):
|
|
| 118 |
initialization_step=initialization_step, max_input_length=max_input_length,
|
| 119 |
vocab_size=vocab_size, attention_mode=attention_mode, pooling=pooling,
|
| 120 |
)
|
| 121 |
-
|
|
|
|
| 122 |
raise ValueError('Unknown decision protocol')
|
| 123 |
-
if decision_protocol == '
|
| 124 |
or code_scheme != 'letters-v1' or attention_mode != 'noncausal_full_attention'):
|
| 125 |
-
raise ValueError('
|
| 126 |
self.decision_protocol = decision_protocol
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 127 |
self._sync_text_causality()
|
| 128 |
if auto_map is not None:
|
| 129 |
self.auto_map = auto_map
|
|
@@ -137,22 +165,36 @@ class LemonDeciderConfig(Qwen3_5Config):
|
|
| 137 |
data = object.__getattribute__(self, "__dict__")
|
| 138 |
if data.get("backbone_type") == "llama":
|
| 139 |
return data["llama_config"]
|
|
|
|
|
|
|
| 140 |
return super().__getattribute__(name)
|
| 141 |
|
| 142 |
@property
|
| 143 |
def inner_backbone_config(self):
|
| 144 |
if getattr(self, "backbone_type", "qwen3_5") == "llama":
|
| 145 |
return self.llama_config
|
|
|
|
|
|
|
| 146 |
return self
|
| 147 |
|
| 148 |
def _sync_text_causality(self):
|
| 149 |
"""Qwen3.5 full-attention reads is_causal from the nested text config."""
|
|
|
|
|
|
|
|
|
|
| 150 |
if getattr(self, "backbone_type", "qwen3_5") != "qwen3_5":
|
| 151 |
return
|
| 152 |
text = super().__getattribute__("text_config")
|
| 153 |
text.is_causal = self.attention_mode == "causal"
|
| 154 |
|
| 155 |
def to_dict(self):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 156 |
if getattr(self, "backbone_type", "qwen3_5") == "llama":
|
| 157 |
output = PreTrainedConfig.to_dict(self)
|
| 158 |
output["backbone_type"] = "llama"
|
|
|
|
| 1 |
+
# Author:忍把浮名,换了浅斟低唱
|
| 2 |
+
"""Configuration for Qwen, Llama or Spark with a dynamic-option decision head."""
|
| 3 |
import math
|
| 4 |
from transformers.configuration_utils import PreTrainedConfig
|
| 5 |
from transformers.models.llama.configuration_llama import LlamaConfig
|
| 6 |
from transformers.models.qwen3_5.configuration_qwen3_5 import Qwen3_5Config
|
| 7 |
+
Spark2_5Config = None # Spark backbone is not part of this Qwen3.5 export
|
| 8 |
|
| 9 |
|
| 10 |
_LLAMA_KEYS = {
|
|
|
|
| 84 |
def __init__(self, codes=None, token_ids=None, max_options=255, temperature=1.0,
|
| 85 |
base_model="Qwen/Qwen3.8-27B", initialization_step=0,
|
| 86 |
max_input_length=8192, code_scheme="letters-v1",
|
| 87 |
+
backbone_type=None, llama_config=None, spark_config=None,
|
| 88 |
+
attention_mode="causal", pooling="last", decision_protocol="lemondecider-v1",
|
| 89 |
+
joint_readout=None, **kwargs):
|
| 90 |
# auto_map is the serialized trust_remote_code contract of every published
|
| 91 |
# checkpoint: the serving/eval stack reloads exported configs via AutoModel.
|
| 92 |
# Stash instead of dropping it, then re-attach after the base constructors
|
|
|
|
| 99 |
if "torch_dtype" in kwargs and "dtype" not in kwargs:
|
| 100 |
kwargs["dtype"] = kwargs.pop("torch_dtype")
|
| 101 |
llama_mode = _llama_requested(backbone_type, llama_config, kwargs)
|
| 102 |
+
if backbone_type == 'spark2_5' or spark_config is not None:
|
| 103 |
+
if backbone_type not in (None, 'spark2_5') or llama_config is not None:
|
| 104 |
+
raise ValueError('Conflicting Spark backbone configuration')
|
| 105 |
+
inner = Spark2_5Config(**dict(spark_config or {}))
|
| 106 |
+
kwargs.pop('text_config', None)
|
| 107 |
+
kwargs.pop('vision_config', None)
|
| 108 |
+
PreTrainedConfig.__init__(self, **kwargs)
|
| 109 |
+
object.__setattr__(self, 'backbone_type', 'spark2_5')
|
| 110 |
+
object.__setattr__(self, 'spark_config', inner)
|
| 111 |
+
vocab_size = inner.vocab_size
|
| 112 |
+
elif llama_mode:
|
| 113 |
if attention_mode != "causal":
|
| 114 |
raise ValueError("noncausal_full_attention is only implemented for the Qwen3.5 hybrid backbone")
|
| 115 |
inner = _llama_from_kwargs(llama_config, kwargs)
|
|
|
|
| 131 |
initialization_step=initialization_step, max_input_length=max_input_length,
|
| 132 |
vocab_size=vocab_size, attention_mode=attention_mode, pooling=pooling,
|
| 133 |
)
|
| 134 |
+
# This published v3 package accepts only its canonical protocol identifier.
|
| 135 |
+
if decision_protocol != 'lemondecider-v1':
|
| 136 |
raise ValueError('Unknown decision protocol')
|
| 137 |
+
if decision_protocol == 'd3-v1' and (self.backbone_type not in ('qwen3_5', 'spark2_5') or max_options != 255
|
| 138 |
or code_scheme != 'letters-v1' or attention_mode != 'noncausal_full_attention'):
|
| 139 |
+
raise ValueError('D3 requires Qwen3.5 or Spark, 255 letter codes and noncausal full attention')
|
| 140 |
self.decision_protocol = decision_protocol
|
| 141 |
+
# Opt-in joint inline readout (configure-> PPLX v1.2 protocol version 3, implemented by
|
| 142 |
+
# joint_readout.py). Declared by an exported checkpoint; None keeps the legacy
|
| 143 |
+
# last-token readout. The declaration is checked structurally, without importing
|
| 144 |
+
# joint_readout: transformers' dynamic-module loader resolves every `from .X import`
|
| 145 |
+
# line as a required file, and that module must stay optional for old checkpoints.
|
| 146 |
+
if joint_readout is not None:
|
| 147 |
+
if (not isinstance(joint_readout, dict) or joint_readout.get('version') != 3
|
| 148 |
+
or joint_readout.get('template') != 'joint-question-inline-readout-v1'
|
| 149 |
+
or joint_readout.get('marker') != '<|fim_suffix|>'
|
| 150 |
+
or joint_readout.get('readout_offset') != 0):
|
| 151 |
+
raise ValueError('Unknown joint readout protocol declaration')
|
| 152 |
+
if attention_mode != 'noncausal_full_attention' or pooling != 'last':
|
| 153 |
+
raise ValueError('Joint inline readout requires noncausal full attention and last-position pooling')
|
| 154 |
+
self.joint_readout = joint_readout
|
| 155 |
self._sync_text_causality()
|
| 156 |
if auto_map is not None:
|
| 157 |
self.auto_map = auto_map
|
|
|
|
| 165 |
data = object.__getattribute__(self, "__dict__")
|
| 166 |
if data.get("backbone_type") == "llama":
|
| 167 |
return data["llama_config"]
|
| 168 |
+
if data.get("backbone_type") == "spark2_5":
|
| 169 |
+
return data["spark_config"]
|
| 170 |
return super().__getattribute__(name)
|
| 171 |
|
| 172 |
@property
|
| 173 |
def inner_backbone_config(self):
|
| 174 |
if getattr(self, "backbone_type", "qwen3_5") == "llama":
|
| 175 |
return self.llama_config
|
| 176 |
+
if self.backbone_type == 'spark2_5':
|
| 177 |
+
return self.spark_config
|
| 178 |
return self
|
| 179 |
|
| 180 |
def _sync_text_causality(self):
|
| 181 |
"""Qwen3.5 full-attention reads is_causal from the nested text config."""
|
| 182 |
+
if self.backbone_type == 'spark2_5':
|
| 183 |
+
self.spark_config.attention_mode = self.attention_mode
|
| 184 |
+
return
|
| 185 |
if getattr(self, "backbone_type", "qwen3_5") != "qwen3_5":
|
| 186 |
return
|
| 187 |
text = super().__getattribute__("text_config")
|
| 188 |
text.is_causal = self.attention_mode == "causal"
|
| 189 |
|
| 190 |
def to_dict(self):
|
| 191 |
+
if getattr(self, 'backbone_type', 'qwen3_5') == 'spark2_5':
|
| 192 |
+
output = PreTrainedConfig.to_dict(self)
|
| 193 |
+
output['backbone_type'] = 'spark2_5'
|
| 194 |
+
output['spark_config'] = self.spark_config.to_dict()
|
| 195 |
+
for name in ('text_config', 'vision_config', 'llama_config'):
|
| 196 |
+
output.pop(name, None)
|
| 197 |
+
return output
|
| 198 |
if getattr(self, "backbone_type", "qwen3_5") == "llama":
|
| 199 |
output = PreTrainedConfig.to_dict(self)
|
| 200 |
output["backbone_type"] = "llama"
|