Word2vec Multithreading (TensorFlow)

Source: Internet
Author: User

Workers = []

For _ in Xrange (opts.concurrent_steps):

t = Threading. Thread (Target=self._train_thread_body)

T.start ()

Workers.append (t)

??

??

the word2vec.py uses multithreading

It is generally considered that Python multithreading is a single thread due to Python's design GPL memory is not ready to secure

but this is because it calls the C + + code Internally, so it can be multithreaded .

??

while Word2vec 's skipgramoperator internal class design solves the problem of multi-threaded access violation is the lock

Mutex mu_;

Random::P hiloxrandom philox_ guarded_by (mu_);

Random::simplephilox rng_ guarded_by (mu_);

Int32 Current_epoch_ guarded_by (mu_) =-1;

Int64 total_words_processed_ guarded_by (mu_) = 0;

Int32 Example_pos_ guarded_by (mu_);

Int32 Label_pos_ guarded_by (mu_);

Int32 label_limit_ guarded_by (mu_)

??

It is thought that the operator operation is a single-threaded parallel execution due to the lock

The batch calculations that follow are parallel

def _train_thread_body (self):

Initial_epoch, = Self._session.run ([Self._epoch])

While True:

_, Epoch = Self._session.run ([Self._train, Self._epoch])

If epoch! = Initial_epoch:

BreaK

??

(words, counts, Words_per_epoch, Self._epoch, self._words, examples,

Labels) = Word2vec.skipgram (Filename=opts.train_data,

Batch_size=opts.batch_size,

Window_size=opts.window_size,

Min_count=opts.min_count,

Subsample=opts.subsample

??

??

??

The threading lock only affects? PythonCode. If your thread is waiting for disk I/O or if it is calling C functions (e.g. via math Library) You can ignore the GIL.

You are able to use the async pattern to get around threading limits. Can You supply more information on what the your program actually does?

I have issues with the technical accuracy of the video linked. David Beazley has the do many well respected talks on the GIL at various pycons. You can find them on pyvideo.org.

??

From

??

??

Word2vec Multithreading (TensorFlow)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.