Repository navigation
Decision: batch the prompts of a request with slice_logits_to_keep - #50548
ArthurZucker wants to merge 7 commits into
Conversation
|
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. |
…eline when remote code is refused
|
Speedup on
FA2 is |
|
# tests/test_decision_head_common.py, in check_decision
placement = {} if "device_map" in pipeline_kwargs else {"device": torch_device}
decide = pipeline(..., **placement, **pipeline_kwargs) # instead of device=torch_device
# tests/models/jev/test_modeling_jev.py
def test_deciders(self):
for repo, expected in DECIDERS.items():
with self.subTest(repo):
check_decision(self, None, repo, expected, atol=1e-2, device_map="auto")
cleanup(torch_device, gc_collect=True) |
|
@ArthurZucker |
|
[For maintainers] Suggested jobs to run (before merge) run-slow: jev |
| "attention_mask": pad_sequence([torch.ones_like(read, dtype=torch.long) for read in reads], batch_first=True), | ||
| "logits_to_keep": pad_sequence(reads, batch_first=True), | ||
| } | ||
| for key in inputs[0].keys() - {"marks", "attention_mask"}: |
There was a problem hiding this comment.
This only looks at the first input for its keys, but it should arguably look at all of them?
Right now if a single input has an image and it is the first of the batch, then it will fail on the following ones. If it's not the first of the batch, then that input's image will be skipped.
| for key in inputs[0].keys() - {"marks", "attention_mask"}: | ||
| values = [prompt[key] for prompt in inputs] | ||
| if values[0].shape[-1] == inputs[0]["input_ids"].shape[-1]: # per token: `input_ids`, `mm_token_type_ids`... | ||
| batch[key] = pad_sequence([value[0] for value in values], batch_first=True) |
There was a problem hiding this comment.
fun gotcha here: if a processor's output's last dimension can equal the length of the first prompt, then this won't work well as it won't concatenate stuff together but instead treat it as per-token and pad it, keeping only its first row per prompt.
example of where it fails:
import torch
from transformers.decision.modeling_utils import batch_prompts
def prompt(seq_len):
return {"input_ids": torch.ones(1, seq_len, dtype=torch.long), "marks": torch.tensor([seq_len]),
"pixel_values": torch.randn(4, 1176)}
print(batch_prompts([(prompt(1175), []), (prompt(1175), [])])["pixel_values"].shape) # (8, 1176): correct
print(batch_prompts([(prompt(1176), []), (prompt(1176), [])])["pixel_values"].shape) # (2, 1176): incorrect(1176 was chosen here as that's the value Qwen2.5 VL uses)
|
This PR might need docs.
Pages that might need an update:
Posted automatically after approval. Docs live in |
One right-padded forward per request; the token before each mark is read with
slice_logits_to_keep, for decision models and generic chat models.