Find Peak Element 寻找峰值
Find Peak
Element
给定一个数组,其中任意两个相邻元素的值不等,寻找数组中某峰值的index
i,使得n[i - 1] < n[i] > n[i + 1]
。保证峰值一定存在,如果有多个峰值,可返回任意一个。
乍看此题不难,O(n)的算法很容易想到,直接遍历数组即可。但题目要求给出O(log(n))的算法。显然,直观上应该用二分查找,否则复杂度要求不能满足。可数组是无序的,无法直接应用二分查找。
Find Peak
Element
给定一个数组,其中任意两个相邻元素的值不等,寻找数组中某峰值的index
i,使得n[i - 1] < n[i] > n[i + 1]
。保证峰值一定存在,如果有多个峰值,可返回任意一个。
乍看此题不难,O(n)的算法很容易想到,直接遍历数组即可。但题目要求给出O(log(n))的算法。显然,直观上应该用二分查找,否则复杂度要求不能满足。可数组是无序的,无法直接应用二分查找。
Today I found that some pods in kubernetes cluster are failed, the
status is Waiting: ContainerCreating
. The pod events:
MountVolume.SetUp failed for volume "xxxxx" : secret "xxxxx" not found
kubelet aks-agentpool-xxx-vmss000001
Unable to attach or mount volumes: unmounted volumes=[xxxxx], unattached volumes=[xxxxx]: timed out waiting for the condition
维护过中型以上系统的工程师,一定都有看到某处代码或设计后脱口而出"What the fuck","这TMD是谁设计的系统","写这代码的人脑子有坑吧?"的经历。
想到上学时一个工作几年的师兄聊天时说,实际系统里讲究“够用就好”,不要搞一些奇技淫巧,当年听起来觉得很有道理,但却没有切身体会。随着经验的积累,慢慢明白什么叫“够用就好”,什么叫过度设计,以及简单比复杂需要更高技巧和更多思考的道理。
There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies. The first method is far more difficult.
GPT2是一个很好的长文本生成模型,但官方版本并没有开源中文预训练好的模型。因此,最近用开源的中文新闻,wiki,评论等从头训练了一个中文GPT2用于文本生成任务。
预训练使用的是HuggingFace的transformers库,这库是个好东西,把当前主流的transfomer-based模型都封装了一遍,使用起来方便很多。但由于不同模型的结构、参数等等细节不同,封装成统一的interface还是有难度,因此此库上也有一些折衷,也并不像想像中那么好使。就pretrain和fine-tune来说,都是训练一个language model,理论上调用它examples/run_language_modeling.py即可。不过真训练起来发现还是有些坑:
最后一个问题坑有点深,nvidia的apex库用起来并不是那么顺滑,尝试了多次并未成功。此外听朋友说即使fp16也仅能提升约20%的训练速度,看起来并不太promising。另外inference时也要使用apex,增加了额外依赖,麻烦。
这里就说说前两个问题。
Windows下的emacs用起来体验不是太好,对中文的支持也不太行。偶尔打开一次需要输入个中文发现用Ctrl+Space或Win+Space都调不出第三方输入法(如腾讯或搜狗输入法)。
忘了在哪看到过一个简单解决方案:在emacs窗口中,按住Ctrl的同时按下鼠标左键会出现一个Buffer Menu,然后随意点一下别处将此Menu消除,再用预设的输入法切换快捷键(Ctrl+Space或Win+Space之类)即可。
感慨一句,emacs最近用得越来越少,尤其是在有了VSCode Remote Development Extention之后,在Windows下远程SSH到Linux下开发便捷许多,甚至可以远程像本地一样运行和DEBUG。
现在用emacs基本是SSH Linux时编辑些配置文件,不再有以前折腾各种插件和炫酷效果的激情,追求的是光速启动和直达目标,用的是肌肉记忆快捷键的情怀:-)
Recently, I found there were huge amount of files named
.com.google.Chrome.*
be created in my /tmp folder.
Obviously the culprit is Chrome. However, after some research no
solution is found to prevent Chrome creating these garbage.
/tmp$ du -csh .com.google.Chrome.*
8.0K .com.google.Chrome.00OKwD
104K .com.google.Chrome.013jYf
172K .com.google.Chrome.015x5t
...
48K .com.google.Chrome.Zytrhf
16K .com.google.Chrome.zz233G
36K .com.google.Chrome.ZzrsZY
163M total
/tmp$ find /tmp -name ".com.google.Chrome*" -ls| wc -l
3468
Update 2020/12/12 I found there are lots of
.com.google.Chrome.*
files in
/tmp/snap.chromium/tmp
:-( . Look at the
ncdu
results:
--- /tmp/snap.chromium/tmp -------------------------------------------------------------------------
/..
4.1 MiB [##########] /.com.google.Chrome.xTBobr
4.1 MiB [######### ] /.com.google.Chrome.0hcsFR
4.0 MiB [######### ] /.com.google.Chrome.YdhzL5
4.0 MiB [######### ] /.com.google.Chrome.nJ5W3A
4.0 MiB [######### ] /.com.google.Chrome.unS6es
...
Total disk usage: 6.8 GiB Apparent size: 12.1 GiB Items: 482530
Now the cleanup script has been
updated.
正确使用异常处理可以让代码逻辑变得清晰,使程序的鲁棒性更好,并可以准确捕捉到一些细节的错误。那么问题来了,异常的使用场景是什么,实践中又有哪些常见问题,本文简单讨论一二。
Yesterday, when I login to my VM I found that the disk is full. Even
a tab command completion cannot be done. I immediately delete some
unused files and the system works. However, when I reboot the system, it
stucked at
A start job is running for Create Volatile Files and Directories...
:
按习惯在HOME中添加了.bashrc文件,定义一些alias和PS1,结果发现putty登录之后并未生效,还须手动source .bashrc
,在~/
目录增加.bash_profile或.profile解决: