Skip to content
This repository was archived by the owner on Jun 11, 2026. It is now read-only.

detokenization parallelization - #37

Open
NickNickGo wants to merge 17 commits into
microsoft:mainfrom
NickNickGo:detokenization
Open

detokenization parallelization#37
NickNickGo wants to merge 17 commits into
microsoft:mainfrom
NickNickGo:detokenization

Conversation

@NickNickGo

Copy link
Copy Markdown
Contributor

Async detokenization

@NickNickGo
NickNickGo requested a review from a teamSeptember 8, 2020 22:18

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If #26 is there with this multi-process change?

Comment threadfastseq_cli/transformers_generate.py
Comment threadfastseq_cli/transformers_generate.py Outdated
Comment threadfastseq_cli/transformers_generate.py Outdated

@feihugisFei Hu (feihugis) left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

NickNickGo It looks good to me in general. One major question is about the output order. We need to make sure the output order as same as before.

Comment threadfastseq_cli/transformers_generate.py
Comment threadfastseq_cli/transformers_generate.py Outdated
Comment threadfastseq_cli/transformers_generate.py Outdated
Comment threadfastseq_cli/transformers_generate.py Outdated
Comment threadfastseq_cli/transformers_generate.py Outdated
Comment threadfastseq_cli/transformers_generate.py Outdated
data_queue = Queue()
msg_queue = Queue()
p_list = []
threads = cpu_count()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It may be better to allow users to specify CPU numbers.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

shouldn't make a big difference right, although I can create an argument .,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

There should be some differences. It will waste the CPU resources and it also brings overhead to create and manage these processes and sync data across these processes.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

There is a parameter define when support parallel for fairseq. GPU machine has 32/64 or more CPU. Do you get better speed when have threads > 1?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Fei Hu (@feihugis) I added support for this.
Yu Yan (@yuyan2do) , I haven't yet analyzed effect of changing num of threads on speed, let me do that .

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

I didn't notice significant changes in overall time when number of threads are changed.

Comment threadfastseq_cli/transformers_generate.py Outdated
Comment threadfastseq_cli/transformers_generate.py Outdated

class IOProcess (Process) :
""" Write detokenized output to file in order."""
def __init__ (self, msg_queue, fout):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
def__init__(self, msg_queue, fout):
def__init__(self, msg_queue, fout):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Remove the similar spaces in other places.

Comment threadfastseq_cli/transformers_generate.py Outdated
def run (self) :
while (True) :
ind, dec = self.msg_queue.get()
if dec == GENERATE_FINISHED :

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
ifdec==GENERATE_FINISHED:
ifdec==GENERATE_FINISHED:

Comment threadfastseq_cli/transformers_generate.py Outdated
Comment threadfastseq_cli/transformers_generate.py Outdated
Comment threadfastseq_cli/transformers_generate.py Outdated
Comment threadfastseq_cli/transformers_generate.py
Comment threadfastseq_cli/transformers_generate.py Outdated
Comment threadfastseq_cli/transformers_generate.py Outdated
Comment threadfastseq_cli/transformers_generate.py Outdated
@NickNickGo

Copy link
Copy Markdown
ContributorAuthor

Linting checks are clean. Could you please add additional formatting requirements (if any) in rcfile, this will reduce formatting iterations.

@feihugis

Fei Hu (feihugis) commented Sep 14, 2020

Copy link
Copy Markdown
Contributor

Linting checks are clean. Could you please add additional formatting requirements (if any) in rcfile, this will reduce formatting iterations.

Good suggestion. The rcfile is enhanced here(#38). One thing it does not cover is the whitespace between 1) function name and parentheses; 2) variables and colon, which you need to manually check and remove but it should be easy.

Comment threadbenchmarks/models/hf_mbart.sh
Comment threadfastseq_cli/transformers_generate.py Outdated
@NickNickGo

NickNickGo commented Sep 25, 2020

Copy link
Copy Markdown
ContributorAuthor

Multi-worker preprocess : Bart Large BS 128 1k samples, throughput change from 11.8 (from #40 ) to 12.3.

@feihugisFei Hu (feihugis) left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Will the numbers in the benchmarking scripts need to be updated?

Comment threadfastseq_cli/transformers_generate.py Outdated
Comment threadfastseq_cli/transformers_generate.py Outdated
Comment on lines +32 to +34
return_tensors="pt",
truncation=True,
padding="max_length")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Add these parameters to the constructor instead of hard coding.

Comment threadfastseq_cli/transformers_generate.py Outdated
Comment threadfastseq_cli/transformers_generate.py Outdated
@NickNickGo

Copy link
Copy Markdown
ContributorAuthor

Fei Hu (@feihugis) thanks, I incorporated all nitpicks.

@feihugisFei Hu (feihugis) left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Last comments: 1) update the benchmarking scripts as this PR will change the performance of all the transformers models; 2) add the docs for the new classes and public APIs (e.g. short description of the API, the types and meaning of the input args and returns).

Comment threadfastseq_cli/transformers_generate.py Outdated
Comment on lines +18 to +25
def __init__(self, examples, tokenizer, model_name, prefix):
self.examples = examples
self.tokenizer= tokenizer
self.model_name = model_name
self.prefix = prefix
self.return_tensors="pt"
self.truncation=True
self.padding="max_length"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I mean something like

def _init(self, examples, tokenizer, model_name, prefix, return_tensors, truncation, padding):
...
self.return_tensors = return_tensors
...

@NickNickGo

Copy link
Copy Markdown
ContributorAuthor

Only HF benchmarks:

Before (without #40 , #37 )

ModelW/O FastSeq (in samples/s)W/ FastSeq (in samples/s)Speedup
Bart (hf)3.48.12.4x
DistilBart (hf)4.08.52.1x
T5 (hf)4.87.51.6x

After:

ModelW/O FastSeq (in samples/s)W/ FastSeq (in samples/s)Speedup
Bart (hf)3.411.03.2x
DistilBart (hf)4.013.53.4x
T5 (hf)4.817.03.5x

@feihugis

Copy link
Copy Markdown
Contributor

NickNickGo One minor question: are the numbers in the benchmark scripts based on #40 or not? If not, the benchmark script may fail when both PRs are merged.

Comment on lines +30 to +31
self.return_tensors="pt"
self.truncation=True

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why use hard code here? We can put these two as the parameters of the constructor.


class IOProcess (Process):
""" Write detokenized output to file in order."""
def __init__(self, msg_queue, fout):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

missing docs


class PostProcess(Process):
""" Parallel detokenization """
def __init__(self, tokenizer, data_queue, msg_queue,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

missing docs.

Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@NickNickGo@feihugis@yuyan2do@JiushengChen