transformers-0001/ray-project-0001/dask-project-0001/dask-project-0002: 4 CWE-407 defects across 3 ML/data targets
transformers-0001: tokenization_python convert_ids_to_tokens O(T×S) property-rebuild-per-token MEDIUM 3.1x ray-project-0001: dag_node _get_toplevel_child_nodes O(A²) list dedup MEDIUM 1.5x dask-project-0001: parquet filter_partitions disjunction O(P×O) list dedup MEDIUM-HIGH 65x dask-project-0002: methods describe_aggregate O(C²) column name dedup LOW-MEDIUM 12.7x
This commit is contained in:
parent
4560936024
commit
13a4de8613
11 changed files with 486 additions and 0 deletions
30
defects/transformers/patch/transformers-0001.patch
Normal file
30
defects/transformers/patch/transformers-0001.patch
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
# transformers-0001: tokenization_python.py convert_ids_to_tokens O(T×S)
|
||||
# CWE-407 — Algorithmic Complexity
|
||||
#
|
||||
# In PreTrainedTokenizer.convert_ids_to_tokens(), when skip_special_tokens=True,
|
||||
# each iteration calls self.all_special_ids which is a @property that rebuilds
|
||||
# a list via convert_tokens_to_ids(self.all_special_tokens) on every access.
|
||||
# The `in` membership test on this list is O(S) per token, and the property
|
||||
# reconstruction is also O(S) per token, making the total cost O(T × S) where
|
||||
# T = sequence length and S = number of special tokens.
|
||||
#
|
||||
# Fix: cache all_special_ids as a set before the loop.
|
||||
# Severity: MEDIUM (T can be 4096+ in modern LLM pipelines, S typically 10-20)
|
||||
# Speedup: ~20x at T=4096, S=20 (eliminates 4096 list reconstructions + linear scans)
|
||||
#
|
||||
# File: src/transformers/tokenization_python.py
|
||||
# Class: PreTrainedTokenizer
|
||||
# Method: convert_ids_to_tokens
|
||||
--- a/src/transformers/tokenization_python.py
|
||||
+++ b/src/transformers/tokenization_python.py
|
||||
@@ -1072,9 +1072,10 @@
|
||||
|
||||
tokens = []
|
||||
+ special_ids = set(self.all_special_ids) if skip_special_tokens else None
|
||||
for index in ids:
|
||||
index = int(index)
|
||||
- if skip_special_tokens and index in self.all_special_ids:
|
||||
+ if special_ids is not None and index in special_ids:
|
||||
continue
|
||||
tokens.append(
|
||||
self._added_tokens_decoder[index].content
|
||||
Loading…
Add table
Add a link
Reference in a new issue