Inf2.xlarge에서 gpt2 text generation inference 수행

<개념>/Deep learning|2024. 1. 22. 10:42
반응형

첫번째시도(실패)

- hugging face에서 제공하는 pytorch 코드로 돌리면 손을좀 봐야한다. 이유는 해당코드가 gpu/cpu 전용으로 만들어졌기 때문. 

( https://github.com/huggingface/transformers/blob/main/examples/pytorch/text-generation/run_generation.py )

- torch.jit.trace와 torch_neuron.trace는 모두 PyTorch 모델을 최적화하여 pytorch 모델을 TorchScript로 바꿔주는데 사용함. 그런데 전자는 cpu/gpu 용도이고 후자가 inferentia용으로 Nueron 호환 형식으로 변환. 그래서 후자로 변환해줘야함

- 변환해줘도 뉴런코어의 사용률이 0%

 

두번째시도(성공)

- hugging face 를 베이스로한 다른 추론코드를 찾음. 뉴런코어를 잘 사용함. ( https://awsdocs-neuron.readthedocs-hosted.com/en/latest/libraries/transformers-neuronx/transformers-neuronx-developer-guide.html )

- 사용한 aws ami : AMI : Deep Learning AMI Neuron PyTorch 1.13 (Ubuntu 20.04) 20240102

- 아래 실행해주면됨.

# 참조 : https://github.com/aws-neuron/transformers-neuronx
pip install transformers-neuronx --extra-index-url=https://pip.repos.neuron.amazonaws.com
source /opt/aws_neuron_venv_pytorch/bin/activate
python3 sample.py

- 모니터링 참조는 https://awsdocs-neuron.readthedocs-hosted.com/en/latest/tools/neuron-sys-tools/neuron-monitor-user-guide.html

neuron-monitor -c monitor.conf >> output.json

 

반응형

댓글()