Make Word.MergeAll sub-quadratic

Offen
#7,872 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Anfängerfreundlichkeit
42/100
Issue-Typ
Refactoring
Klarheit
Größtenteils klar
Aktivitätsstatus
Aktiv
Tech-Stack
csharp, machine-learning
Bereich
performance

Rechercherichtung

The slow path is Word.MergeAll in src/Microsoft.ML.Tokenizers/Model/Word.cs, where symbols are removed from a Vec<T>-style list with Remove() while a PriorityQueue<T> drives the merges. Read that method first and find which tests in the Microsoft.ML.Tokenizers test project cover BPE merging so you can confirm the output is unchanged. Done means the removal no longer shifts the list on every merge, the existing tokenizer tests still pass, and the change is benchmarked against the old version.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

area-Tokenizers tenet-performance

The current implementation of Word.MergeAll uses Vec<T>.Remove() to remove symbols from the list:

https://github.com/dotnet/machinelearning/blob/81310b23aeee0cc12720edde8794e3cc94afef3e/src/Microsoft.ML.Tokenizers/Model/Word.cs#L187-L194

Based on data I found, it seems it's common that around 75 % of symbols are removed here (though the data conflates multiple steps, so it could be not fully relevant). This makes the method quadratic, likely significantly affecting its performance.

We should consider improving that. (This won't make the method linear, since the use of PriorityQueue<T> leads to at least O(n log n).)

Vorherrschende Sprache
C#
Sterne
9.4k
Forks
2k
Ø Merge
2 T. 18 Std.
Gemergte PRs (30 T.)
64

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus dotnet/machinelearning

Alle Issues in dotnet/machinelearning

Ähnliche Issues

Weitere Issues zu C#

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.