无性能损失,不用更改代码,Lightning 1.1版本发布,切分训练新功能节省50%以上内存
机器之心报道
继 1.0.0 版本推出不到两个月的时间,grid.ai CEO、纽约大学博士 William Falcon 创建的 PyTorch Lightning 于近日宣布推出 1.1 版本。新版本新增了 sharded training 功能,在多 GPU 上训练深度学习(DL)模型时可以节省 50% 以上的内存,并且没有性能损失,也不需要更改代码。
import os
from omegaconf import OmegaConf
# Build a simple word based vocabulary for benchmarking purposes
with open('wikitext-2/train.txt') as f:
vocab = set(f.read().split())
with open('vocab.txt', 'w') as f:
f.write('\n'.join(vocab))
# Define the model configuration using the preset configuration file found within NeMo
config_path = "./examples/nlp/language_modeling/conf/transformer_lm_config.yaml"
config = OmegaConf.load(config_path)
config.model.language_model.vocab_file = 'vocab.txt'
config.model.train_ds.file_name = os.path.join('wikitext-2/train.txt')
config.model.validation_ds.file_name = os.path.join('wikitext-2/valid.txt')
import pytorch_lightning as pl
from nemo.collections import nlp as nemo_nlp
# Set model parameters (roughly 1.2 billion parameters)
config.model.train_ds.batch_size = 8 # Reduce batch size for training large model
config.model.language_model.hidden_size = 3072
config.model.language_model.inner_size = 3072
config.model.language_model.num_layers = 22
# Use 8 GPUs, and enable Mixed Precision + Sharded Training
trainer = pl.Trainer(
gpus=8,
precision=16,
max_epochs=50,
accelerator='ddp',
plugins='ddp_sharded'
)
model = nemo_nlp.models.TransformerLMModel(cfg=config.model, trainer=trainer)
本周日,在北京有一场属于开发者的冬日狂欢。
王海峰、朱军、李宏毅等AI大咖畅聊产业、人才与开源。
30场技术公开课干货满满。 伴手礼人手一份,互动展区还有众多礼品等你来拿。 DJ、乐队、街舞、脱口秀同台 AI 狂欢夜。

© THE END
转载请联系本公众号获得授权
投稿或寻求报道:content@jiqizhixin.com
关注公众号:拾黑(shiheibook)了解更多
[广告]赞助链接:
四季很好,只要有你,文娱排行榜:https://www.yaopaiming.com/
让资讯触达的更精准有趣:https://www.0xu.cn/

随时掌握互联网精彩
赞助链接
排名
热点
搜索指数
- 1 三个层面看我国民营经济发展前景 7975784
- 2 小伙30多万买机器人对外租8000一天 7975404
- 3 《哪吒2》成香港单日票房榜冠军 7803364
- 4 产业“破题” 绘就振兴“答卷” 7736519
- 5 客机西安起飞后返航 引擎冒火光 7607654
- 6 偶像剧终于有不回避成长女主了 7560129
- 7 4人喝100瓶酒1人坠亡 KTV被判赔48万 7475075
- 8 女孩逃票进景区后坠亡 景区被判无责 7320899
- 9 8岁孩子厨房玩刀意外刺破肝脏 7267364
- 10 欧洲多国领导人:俄乌和谈不能缺乌欧 7126121