Word2vec多线程(tensorflow)
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)的更多相关文章
- Word2Vec在Tensorflow上的版本以及与Gensim之间的运行对比
接昨天的博客,这篇随笔将会对本人运行Word2Vec算法时在Gensim以及Tensorflow的不同版本下的运行结果对比.在运行中,参数的调节以及迭代的决定本人并没有很好的经验,所以希望在展出运行的 ...
- word2vec之tensorflow(skip-gram)实现
关于word2vec的理解,推荐文章https://www.cnblogs.com/guoyaohua/p/9240336.html 代码参考https://github.com/eecrazy/wo ...
- Forward-backward梯度求导(tensorflow word2vec实例)
考虑不可分的例子 通过使用basis functions 使得不可分的线性模型变成可分的非线性模型 最常用的就是写出一个目标函数 并且使用梯度下降法 来计算 梯度的下降法的梯度 ...
- Python Tensorflow下的Word2Vec代码解释
前言: 作为一个深度学习的重度狂热者,在学习了各项理论后一直想通过项目练手来学习深度学习的框架以及结构用在实战中的知识.心愿是好的,但机会却不好找.最近刚好有个项目,借此机会练手的过程中,我发现其实各 ...
- tensorflow笔记:流程,概念和简单代码注释
tensorflow是google在2015年开源的深度学习框架,可以很方便的检验算法效果.这两天看了看官方的tutorial,极客学院的文档,以及综合tensorflow的源码,把自己的心得整理了一 ...
- tensorflow加载embedding模型进行可视化
1.功能 采用python的gensim模块训练的word2vec模型,然后采用tensorflow读取模型可视化embedding向量 ps:采用C++版本训练的w2v模型,python的gensi ...
- Tensorflow 模型线上部署
获取源码,请移步笔者的github: tensorflow-serving-tutorial 由于python的灵活性和完备的生态库,使得其成为实现.验证ML算法的不二之选.但是工业界要将模型部署到生 ...
- 学习笔记TF047:PlayGround、TensorBoard
PlayGround.http://playground.tensorflow.org .教学目的简单神经网络在线演示.实验图形化平台.可视化神经网络训练过程.在浏览器训练神经网络.界面,数据(DAT ...
- Word2vec 模型载入(tensorflow)
opts = Options() with tf.Graph().as_default(), tf.Session() as session: model = Word2Vec(opts, sessi ...
随机推荐
- ical4j 实现ICS文件的生成和解析
iCalendar 简介 iCalendar,简称"iCal",是"日历数据交换"的标准(RFC 2445),该标准提供了一种公共的数据格式用于存储关于日历方面 ...
- jQuery链式操作[转]
用过jQuery的朋友都知道他强大的链式操作,方便,简洁,易于理解,如下 $("has_children").click(function(){ $(this).addClass( ...
- JAVA之IO流(字节流)
输入和输出 JAVA的流分为输入流和输出流两部分, 输入流:InputStream或者Reader:从文件中读到程序中: 输出流:OutputStream或者Writer:从程序中输出到文件中: Re ...
- c# 文本框只能输入数字
<input type="text" onKeyUp="value=value.replace(/\D/g,'')" /> onKeyUp: 当输 ...
- bzoj 3262 陌上花开
本质是一个三维偏序,一位排序后cdq分治,一维在子函数里排序,一维用树状数组维护. 把三维相等的合并到一个里面. #include<iostream> #include<cstdio ...
- Startup配置类 居然又是约定
Microsoft.Owin.Host.SystemWeb 这个dll可以让OWin接管IIS的请求,虽然同样是托管在IIS,但是所有的请求都会被OWin来处理.在OWin的4层结构中(Applica ...
- Google 地图 API V3 之 叠加层
Google官方教程: Google 地图 API V3 使用入门 Google 地图 API V3 针对移动设备进行开发 Google 地图 API V3 之事件 Google 地图 API V3 ...
- jquery ajax beforeSend 提交等待问题
需要使用异步加载async : true 否则不会出现等待效果 $.ajax({ url : $('#form').attr("action"), data: $('#form') ...
- 苹果手机IOS中div contenteditable=true 仿文本域无法输入编辑
问题: 在苹果手机IOS中 contenteditable="true" 做文本域输入,点击可以弹出键盘但是无法输入,安卓都正常. 经测试后,记得加一个样式 -webkit-use ...
- 大熊君学习html5系列之------XHR2(XMLHttpRequest Level 2)
一,开篇分析 Hi,大家好!大熊君又和大家见面了,(*^__^*) 嘻嘻……,这系列文章主要是学习Html5相关的知识点,以学习API知识点为入口,由浅入深的引入实例, 让大家一步一步的体会" ...