无性能损失,不用更改代码,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 “共同迎接六国更加美好的明天” 7904354
- 2 酒后推车回家算酒驾吗 交警回应 7807916
- 3 荔枝价格暴跌七成 7714147
- 4 中国高铁又快又稳的秘密 7617011
- 5 韵达快递被罚 7520499
- 6 全球第2个满级QQ也来了 当事人回应 7427413
- 7 以色列总理:已掌控伊朗首都领空 7332697
- 8 茅台跌了 回收商快亏掉一台奔驰 7234432
- 9 35岁抗癌网红“肉肉”去世 7135736
- 10 这届年轻人为什么爱非遗 7043118