workers = []

for _ in xrange(opts.concurrent_steps):

t = threading.Thread(target=self._train_thread_body)

t.start()

workers.append(t)

 
 

 
 

Word2vec.py使用了多线程

一般认为python多线程其实是单线程
由于python的设计 GPL 内存不是现成安全的

但是这里由于内部是调用c++代码
所以还是能起到多线程作用

 
 

而 Word2vec的 skipgramoperator内部类设计
解决多线程访问冲突问题用的是锁

mutex mu_;

random::PhiloxRandom 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_)

 
 

觉得operator的操作还是单线程并行执行的
由于锁

后面的batch计算是并行的

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 Python code. 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 may be able to use the async pattern to get around threading limits. Can you supply more information about what your program actually does?

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

 
 

来自 <https://www.reddit.com/r/Python/comments/3s0vg9/is_my_multithreaded_python_program_doomed/>

 
 

 
 

Word2vec多线程(tensorflow)的更多相关文章

  1. Word2Vec在Tensorflow上的版本以及与Gensim之间的运行对比

    接昨天的博客,这篇随笔将会对本人运行Word2Vec算法时在Gensim以及Tensorflow的不同版本下的运行结果对比.在运行中,参数的调节以及迭代的决定本人并没有很好的经验,所以希望在展出运行的 ...

  2. word2vec之tensorflow(skip-gram)实现

    关于word2vec的理解,推荐文章https://www.cnblogs.com/guoyaohua/p/9240336.html 代码参考https://github.com/eecrazy/wo ...

  3. Forward-backward梯度求导(tensorflow word2vec实例)

    考虑不可分的例子         通过使用basis functions 使得不可分的线性模型变成可分的非线性模型 最常用的就是写出一个目标函数 并且使用梯度下降法 来计算     梯度的下降法的梯度 ...

  4. Python Tensorflow下的Word2Vec代码解释

    前言: 作为一个深度学习的重度狂热者,在学习了各项理论后一直想通过项目练手来学习深度学习的框架以及结构用在实战中的知识.心愿是好的,但机会却不好找.最近刚好有个项目,借此机会练手的过程中,我发现其实各 ...

  5. tensorflow笔记:流程,概念和简单代码注释

    tensorflow是google在2015年开源的深度学习框架,可以很方便的检验算法效果.这两天看了看官方的tutorial,极客学院的文档,以及综合tensorflow的源码,把自己的心得整理了一 ...

  6. tensorflow加载embedding模型进行可视化

    1.功能 采用python的gensim模块训练的word2vec模型,然后采用tensorflow读取模型可视化embedding向量 ps:采用C++版本训练的w2v模型,python的gensi ...

  7. Tensorflow 模型线上部署

    获取源码,请移步笔者的github: tensorflow-serving-tutorial 由于python的灵活性和完备的生态库,使得其成为实现.验证ML算法的不二之选.但是工业界要将模型部署到生 ...

  8. 学习笔记TF047:PlayGround、TensorBoard

    PlayGround.http://playground.tensorflow.org .教学目的简单神经网络在线演示.实验图形化平台.可视化神经网络训练过程.在浏览器训练神经网络.界面,数据(DAT ...

  9. Word2vec 模型载入(tensorflow)

    opts = Options() with tf.Graph().as_default(), tf.Session() as session: model = Word2Vec(opts, sessi ...

随机推荐

  1. springMVC Aspect AOP 接口耗时统计

    在接口开发中,我们通常需要统计接口耗时,为后续接口性能做统计.在springMVC中可以用它的aop来记录日志. 1.在spring配置文件中开启AOP <!--*************** ...

  2. 由Memcached升级到 Couchbase的 Java 客户端的过程记录(一)

    背景: 在项目启动的选用了Memcached 作为缓存服务器,采用了Xmemcached作为客户端.在项目中使用了Shiro,为了给 Shiro 配置缓存的时候,采用了开源代码   https://g ...

  3. JS:offsetWidth\offsetleft 等图文解释

        网页可见区域宽: document.body.clientWidth;网页可见区域高: document.body.clientHeight;网页可见区域宽: document.body.of ...

  4. 向shell脚本中传入参数

    写一个 程序名为    test.sh    可带参数为 start 和 stop 执行  test.sh start执行  start 内容的代码 执行 test.sh stop 执行 stop 内 ...

  5. Nginx反向代理tomcat,seesion会话保持。

    proxy_pass http://10.0.0.10:8081/monitor/; proxy_cookie_path /monitor/ /; proxy_set_header Host &quo ...

  6. 1 云计算系列之云计算概述和KVM虚拟化简介

    为什么会出现云之传统数据中学面临的问题 物理服务器的利用率非常低,浪费资源,且资源分配不合理,比如一台服务器CPU使用率不到40%,或者某个应用需要的硬件配置低但是服务器硬件配置高等等. 云计算概念 ...

  7. 在github上搭建hexo博客

    准备工作 安装git 系统是win10家庭版,采用git v1.9.5版本,比较简单,一路next直到finsh完成安装. 安装node.js hexo是基于node.js驱动的一款快速.简单且功能强 ...

  8. SDL 截图、录像、录像播放

    截图 使用sdl很简单,视频显示窗口大小,不是视频分辨率大小 int i = Sdl.SDL_SaveBMP(surfacePtr, path); if(i != 0) { MessageBox.Sh ...

  9. thinkphp语言包

    1.config.php语言包相关配置. //开启语言包 'LANG_SWITCH_ON' => true, 'LANG_AUTO_DETECT' => true, // 自动侦测语言 开 ...

  10. ReactiveCocoa源码拆分解析(五)

    (整个关于ReactiveCocoa的代码工程可以在https://github.com/qianhongqiang/QHQReactive下载) 好多天没写东西了,今天继续.主要讲解RAC如何于UI ...