| <!--Copyright 2022 The HuggingFace Team. All rights reserved. | |
| Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with | |
| the License. You may obtain a copy of the License at | |
| http://www.apache.org/licenses/LICENSE-2.0 | |
| Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | |
| an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | |
| โ ๏ธ Note that this file is in Markdown but contain specific syntax for our doc-builder (similar to MDX) that may not be | |
| rendered properly in your Markdown viewer. | |
| --> | |
| # CPU์์ ํจ์จ์ ์ธ ํ๋ จ [[efficient-training-on-cpu]] | |
| ์ด ๊ฐ์ด๋๋ CPU์์ ๋๊ท๋ชจ ๋ชจ๋ธ์ ํจ์จ์ ์ผ๋ก ํ๋ จํ๋ ๋ฐ ์ด์ ์ ๋ง์ถฅ๋๋ค. | |
| ## IPEX์ ํผํฉ ์ ๋ฐ๋ [[mixed-precision-with-ipex]] | |
| IPEX๋ AVX-512 ์ด์์ ์ง์ํ๋ CPU์ ์ต์ ํ๋์ด ์์ผ๋ฉฐ, AVX2๋ง ์ง์ํ๋ CPU์๋ ๊ธฐ๋ฅ์ ์ผ๋ก ์๋ํฉ๋๋ค. ๋ฐ๋ผ์ AVX-512 ์ด์์ Intel CPU ์ธ๋์์๋ ์ฑ๋ฅ์ ์ด์ ์ด ์์ ๊ฒ์ผ๋ก ์์๋์ง๋ง, AVX2๋ง ์ง์ํ๋ CPU (์: AMD CPU ๋๋ ์ค๋๋ Intel CPU)์ ๊ฒฝ์ฐ์๋ IPEX ์๋์์ ๋ ๋์ ์ฑ๋ฅ์ ๋ณด์ผ ์ ์์ง๋ง ์ด๋ ๋ณด์ฅ๋์ง ์์ต๋๋ค. IPEX๋ Float32์ BFloat16๋ฅผ ๋ชจ๋ ์ฌ์ฉํ์ฌ CPU ํ๋ จ์ ์ํ ์ฑ๋ฅ ์ต์ ํ๋ฅผ ์ ๊ณตํฉ๋๋ค. BFloat16์ ์ฌ์ฉ์ ๋ค์ ์น์ ์ ์ฃผ์ ์ด์ ์ ๋๋ค. | |
| ์ ์ ๋ฐ๋ ๋ฐ์ดํฐ ํ์ ์ธ BFloat16์ 3์ธ๋ Xeonยฎ Scalable ํ๋ก์ธ์ (์ฝ๋๋ช : Cooper Lake)์์ AVX512 ๋ช ๋ น์ด ์งํฉ์ ๋ค์ดํฐ๋ธ๋ก ์ง์ํด ์์ผ๋ฉฐ, ๋ค์ ์ธ๋์ Intelยฎ Xeonยฎ Scalable ํ๋ก์ธ์์์ Intelยฎ Advanced Matrix Extensions (Intelยฎ AMX) ๋ช ๋ น์ด ์งํฉ์ ์ง์ํ์ฌ ์ฑ๋ฅ์ ํฌ๊ฒ ํฅ์์ํฌ ์์ ์ ๋๋ค. CPU ๋ฐฑ์๋์ ์๋ ํผํฉ ์ ๋ฐ๋ ๊ธฐ๋ฅ์ PyTorch-1.10๋ถํฐ ํ์ฑํ๋์์ต๋๋ค. ๋์์, Intelยฎ Extension for PyTorch์์ BFloat16์ ๋ํ CPU์ ์๋ ํผํฉ ์ ๋ฐ๋ ๋ฐ ์ฐ์ฐ์์ BFloat16 ์ต์ ํ๋ฅผ ๋๊ท๋ชจ๋ก ํ์ฑํํ๊ณ , PyTorch ๋ง์คํฐ ๋ธ๋์น๋ก ๋ถ๋ถ์ ์ผ๋ก ์ ์คํธ๋ฆผ์ ๋ฐ์ํ์ต๋๋ค. ์ฌ์ฉ์๋ค์ IPEX ์๋ ํผํฉ ์ ๋ฐ๋๋ฅผ ์ฌ์ฉํ์ฌ ๋ ๋์ ์ฑ๋ฅ๊ณผ ์ฌ์ฉ์ ๊ฒฝํ์ ์ป์ ์ ์์ต๋๋ค. | |
| [์๋ ํผํฉ ์ ๋ฐ๋](https://intel.github.io/intel-extension-for-pytorch/cpu/latest/tutorials/features/amp.html)์ ๋ํ ์์ธํ ์ ๋ณด๋ฅผ ํ์ธํ์ญ์์ค. | |
| ### IPEX ์ค์น: [[ipex-installation]] | |
| IPEX ๋ฆด๋ฆฌ์ค๋ PyTorch๋ฅผ ๋ฐ๋ผ๊ฐ๋๋ค. pip๋ฅผ ํตํด ์ค์นํ๋ ค๋ฉด: | |
| | PyTorch Version | IPEX version | | |
| | :---------------: | :----------: | | |
| | 1.13 | 1.13.0+cpu | | |
| | 1.12 | 1.12.300+cpu | | |
| | 1.11 | 1.11.200+cpu | | |
| | 1.10 | 1.10.100+cpu | | |
| ```bash | |
| pip install intel_extension_for_pytorch==<version_name> -f https://developer.intel.com/ipex-whl-stable-cpu | |
| ``` | |
| [IPEX ์ค์น](https://intel.github.io/intel-extension-for-pytorch/cpu/latest/tutorials/installation.html)์ ๋ํ ๋ ๋ง์ ์ ๊ทผ ๋ฐฉ๋ฒ์ ํ์ธํ์ญ์์ค. | |
| ### Trainer์์์ ์ฌ์ฉ๋ฒ [[usage-in-trainer]] | |
| Trainer์์ IPEX์ ์๋ ํผํฉ ์ ๋ฐ๋๋ฅผ ํ์ฑํํ๋ ค๋ฉด ์ฌ์ฉ์๋ ํ๋ จ ๋ช ๋ น ์ธ์์ `use_ipex`, `bf16`, `no_cuda`๋ฅผ ์ถ๊ฐํด์ผ ํฉ๋๋ค. | |
| [Transformers ์ง๋ฌธ-์๋ต](https://github.com/huggingface/transformers/tree/main/examples/pytorch/question-answering)์ ์ฌ์ฉ ์ฌ๋ก๋ฅผ ์ดํด๋ณด๊ฒ ์ต๋๋ค. | |
| - CPU์์ BF16 ์๋ ํผํฉ ์ ๋ฐ๋๋ฅผ ์ฌ์ฉํ์ฌ IPEX๋ก ํ๋ จํ๊ธฐ: | |
| <pre> python run_qa.py \ | |
| --model_name_or_path google-bert/bert-base-uncased \ | |
| --dataset_name squad \ | |
| --do_train \ | |
| --do_eval \ | |
| --per_device_train_batch_size 12 \ | |
| --learning_rate 3e-5 \ | |
| --num_train_epochs 2 \ | |
| --max_seq_length 384 \ | |
| --doc_stride 128 \ | |
| --output_dir /tmp/debug_squad/ \ | |
| <b>--use_ipex \</b> | |
| <b>--bf16 --no_cuda</b></pre> | |
| ### ์ค์ต ์์ [[practice-example]] | |
| ๋ธ๋ก๊ทธ: [Intel Sapphire Rapids๋ก PyTorch Transformers ๊ฐ์ํ](https://huggingface.co/blog/intel-sapphire-rapids) |