Skip to content

Conversation

manueldeprada
Copy link
Contributor

@manueldeprada manueldeprada commented Sep 18, 2025

#40657 inadvertently changed an implicit algorithmic bias: candidate_generator (the assistant model) was getting logits_processor while the decoding method (main model) was getting prepared_logits_processor. This meant that the assistant was running with T=1 while the main model was using lower temp.

We investigated and its good for speculation to have a hotter assistant model (so it was a good bug that we were not applying the lower temp to the assistant),

image image image

But it should be explicitly set and not a hidden argument forwarding consequence. This PR does that, setting it by default to 1.5.

This PR also fixes:

FAILED tests/generation/test_utils.py::GenerationIntegrationTests::test_generated_length_assisted_generation - ValueError: Passing `MinLengthLogitsProcessor` when using `assisted_generation is disabled. Please pass in `min_length` into `.generate()` instead

which originates from the same change in LogitsProcessor passing.

Comment on lines +180 to +182
self.logits_processor = [
processor for processor in self.logits_processor if not isinstance(processor, MinLengthLogitsProcessor)
]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Length is controlled by main model's generation loop, so we should just discard those on the assistant right? @gante

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes 👍

(see comment on L175-176)

Comment on lines 3519 to 3532
# Prefer a slightly higher temperature for the assistant when not explicitly provided
idx = next((i for i, p in enumerate(logits_processor) if isinstance(p, TemperatureLogitsWarper)), None)
temp_processor = logits_processor.pop(idx) if idx is not None else TemperatureLogitsWarper(temperature=1.0)

if assistant_temperature is None and temp_processor is not None and temp_processor.temperature < 1.5:
logger.warning_once(
f"The assistant's sampling temperature comes from main generation loop set to {temp_processor.temperature},"
"but speculative decoding benefits from slightly hotter candidate generation, (see #40976)so we are setting it"
"to 1.5. This should improve decoding speed in most cases. Use `assistant_temperature` to override this value."
)
assistant_temperature = 1.5

if assistant_temperature is not None:
logits_processor.insert(0, TemperatureLogitsWarper(temperature=assistant_temperature))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1.5 seems the most balanced for now, subject to change if experiments show otherwise, I am still benchmarking more models.

@HuggingFaceDocBuilderDev

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

Comment on lines 2218 to 2222
"assistant_model": assistant_model,
"streamer": streamer,
"assistant_temperature": kwargs.pop("assistant_temperature", None),
}
generation_mode_kwargs["synced_gpus"] = (
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need to change generate signature!! it gets automatically forwarded.

In fact, we could remove assistant_model from the signature (👀 v5?) and all the decoding method-specific kwargs get automatically forwarded.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no signature change, but it's still an argument (that should be documented)

In any case, I'd rather have it being controlled by assistant_model.generation_config.temperature, in AssistedCandidateGenerator.__init__ -- if it's the default value (1.0), or == main model temperature, then override.

Copy link
Member

@gante gante left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A big question below 👀

Comment on lines +180 to +182
self.logits_processor = [
processor for processor in self.logits_processor if not isinstance(processor, MinLengthLogitsProcessor)
]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes 👍

(see comment on L175-176)

Comment on lines +3519 to +3532
# Prefer a slightly higher temperature for the assistant when not explicitly provided
idx = next((i for i, p in enumerate(logits_processor) if isinstance(p, TemperatureLogitsWarper)), None)
temp_processor = logits_processor.pop(idx) if idx is not None else TemperatureLogitsWarper(temperature=1.0)

if assistant_temperature is None and temp_processor is not None and temp_processor.temperature < 1.5:
logger.warning_once(
f"The assistant's sampling temperature comes from main generation loop set to {temp_processor.temperature}, "
"but speculative decoding benefits from slightly hotter candidate generation, (see #40976) so we are setting it "
"to 1.5. This should improve decoding speed in most cases. Use `assistant_temperature` to override this value."
)
assistant_temperature = 1.5

if assistant_temperature is not None:
logits_processor.insert(0, TemperatureLogitsWarper(temperature=assistant_temperature))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doesn't this change the temperature for both models? 👀 (logits_processor also used in step 2.3)

Comment on lines 2218 to 2222
"assistant_model": assistant_model,
"streamer": streamer,
"assistant_temperature": kwargs.pop("assistant_temperature", None),
}
generation_mode_kwargs["synced_gpus"] = (
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no signature change, but it's still an argument (that should be documented)

In any case, I'd rather have it being controlled by assistant_model.generation_config.temperature, in AssistedCandidateGenerator.__init__ -- if it's the default value (1.0), or == main model temperature, then override.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants