Views
No views yet
$MYDIR and defined as (in bash):export MYDIR=$HOMETransformers.git clone https://github.com/huggingface/transformers.git $MYDIR/transformersnvidia/megatron-gpt2-345m:mkdir -p $MYDIR/nvidia/megatron-gpt2-345mwget --content-disposition https://api.ngc.nvidia.com/v2/models/nvidia/megatron_lm_345m/versions/v0.0/zip -O $MYDIR/nvidia/megatron-gpt2-345m/checkpoint.zipTransformers, the checkpoint has to be converted. You should run the following command for that purpose.
That command will create config.json and pytorch_model.bin in $MYDIR/nvidia/megatron-gpt2-345m.
You can move those files to different directories if needed.python3 $MYDIR/transformers/src/transformers/models/megatron_gpt2/convert_megatron_gpt2_checkpoint.py $MYDIR/nvidia/megatron-gpt2-345m/checkpoint.zipModuleNotFoundError: No module named 'megatron.model.enums'cd /tmp
git clone https://github.com/NVIDIA/Megatron-LM
PYTHONPATH=/tmp/Megatron-LM python src/transformers/models/megatron_bert/convert_megatron_bert_checkpoint.py ...import os
import torch
from transformers import GPT2Tokenizer, GPT2LMHeadModel
# The tokenizer. Megatron was trained with standard tokenizer(s).
tokenizer = GPT2Tokenizer.from_pretrained('gpt2')
# The path to the config/checkpoint (see the conversion step above).
directory = os.path.join(os.environ['MYDIR'], 'nvidia/megatron-gpt2-345m')
# Load the model from $MYDIR/nvidia/megatron-gpt2-345m.
model = GPT2LMHeadModel.from_pretrained(directory)
# Copy to the device and use FP16.
assert torch.cuda.is_available()
device = torch.device("cuda")
model.to(device)
model.eval()
model.half()
# Generate the sentence.
output = model.generate(input_ids=None, max_length=32, num_return_sequences=1)
# Output the text.
for sentence in output:
sentence = sentence.tolist()
text = tokenizer.decode(sentence, clean_up_tokenization_spaces=True)
print(text)wget --content-disposition https://api.ngc.nvidia.com/v2/models/nvidia/megatron_lm_345m/versions/v0.0/zip -O megatron_lm_345m_v0.0.zippython src/transformers/models/megatron_gpt2/convert_megatron_gpt2_checkpoint.py megatron_lm_345m_v0.0.zipgit clone https://huggingface.co/nvidia/megatron-gpt2-345m/mv config.json pytorch_model.bin megatron-gpt2-345m/megatron-gpt2-345m dir should now have all the files which can be passed to HF Trainer as --model_name_or_path megatron-gpt2-345m