无性能损失,不用更改代码,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 一封特殊的入党批复函 7903960
- 2 山东舰抵达香港 甲板上停满舰载机 7808708
- 3 中日友好医院最新发声:深刻反思 7712678
- 4 闻“汛”而动 冲锋在前 7618553
- 5 “本升专”竟然成真了 7521846
- 6 《亮剑》原班人马拍短剧 7426525
- 7 高考志愿填报启动 网警继续护航 7334026
- 8 埃菲尔铁塔被热到弯曲偏斜 7238397
- 9 上海一大学学费15万1年 校方:不盈利 7140611
- 10 28岁女子做取环手术致十级伤残 7041042