Skip to content

recipes_source/quantization.rst 번역 #589

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Sep 11, 2022

Conversation

hjvision96
Copy link
Contributor

라이선스 동의

변경해주시는 내용에 BSD 3항 라이선스가 적용됨을 동의해주셔야 합니다.

더 자세한 내용은 기여하기 문서를 참고해주세요.

동의하시면 아래 [ ][x]로 만들어주세요.

  • 기여하기 문서를 확인하였으며, 본 PR 내용에 BSD 3항 라이선스가 적용됨에 동의합니다.

관련 이슈 번호

이 Pull Request와 관련있는 이슈 번호를 적어주세요.

이슈 또는 PR 번호 앞에 #을 붙이시면 제목을 바로 확인하실 수 있습니다. (예. #999 )

PR 종류

이 PR에 해당되는 종류 앞의 [ ][x]로 변경해주세요.

  • 오탈자를 수정하거나 번역을 개선하는 기여
  • 번역되지 않은 튜토리얼을 번역하는 기여
  • 공식 튜토리얼 내용을 반영하는 기여
  • 위 종류에 포함되지 않는 기여

PR 설명

이 PR로 무엇이 달라지는지 대략적으로 알려주세요.
recipes_source/quantization.rst를 번역하였습니다.


After a quantized model is generated using one of the steps above, before the model can be used to run on mobile devices, it needs to be further converted to the `TorchScript` format and then optimized for mobile apps. See the `Script and Optimize for Mobile recipe <script_optimized.html>`_ for details.
위의 단계 중 하나를 이용해 양자화된 모델이 생성된 후에, 모바일 장치에서 작동되게 하려면 추가로 `TorchScript` 형식으로 전환하고 모바일 app에 최적화를 진행해야 합니다. 자세한 내용은 `Script and Optimize for Mobile recipe <script_optimized.html>`_\를 확인하세요.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Script and Optimize for Mobile recipe <script_optimized.html>
해당 문서가 아직 번역이 안된 상태입니다. Script and Optimize for Mobile recipe 를 제가 번역하여 적어야 할까요?
이후에 다른 분이 번역을 다르게 하면 충돌이 되나 걱정이 됩니다. 의견 부탁드립니다~!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

지금처럼 원문 그대로 적으시면 될 것 같습니다~

Copy link
Contributor

@updaun updaun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

대체적으로 번역이 매끄럽게 잘 된 것 같습니다. 고생하셨습니다!

Copy link
Contributor

@terri1102 terri1102 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

매끄럽게 잘 번역하신 것 같습니다. 수고하셨습니다~

@hyoyoung hyoyoung added the 컨트리뷰톤 오픈소스 컨트리뷰톤 관련 이슈/PR label Sep 4, 2022
Copy link
Contributor

@YunjinJo YunjinJo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

수정사항 남겼습니다!


Quantization is a technique that converts 32-bit floating numbers in the model parameters to 8-bit integers. With quantization, the model size and memory footprint can be reduced to 1/4 of its original size, and the inference can be made about 2-4 times faster, while the accuracy stays about the same.
양자화는 모델 매개변수를 구성하는 32-비트 크기의 실수 자료형의 숫자를 8-비트 크기의 정수 자료형의 숫자로 전환하는 기법입니다. 양자화 기법을 적용하면, 정확도는 거의 같게 유지하면서, 모델의 크기와 메모리 전체 사용량을 원본 모델의 4분의 1까지 감소시킬 수 있고, 추론은 2~4배 정도 빠르게 만들 수 있습니다.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

32-비트 -> 32비트, 8-비트 -> 8비트
영문법에서는 숫자 표현시 하이픈을 쓰지만, 한국어 문법은 아닌걸로 알고있습니다.


There are overall three approaches or workflows to quantize a model: post training dynamic quantization, post training static quantization, and quantization aware training. But if the model you want to use already has a quantized version, you can use it directly without going through any of the three workflows above. For example, the `torchvision` library already includes quantized versions for models MobileNet v2, ResNet 18, ResNet 50, Inception v3, GoogleNet, among others. So we will make the last approach another workflow, albeit a simple one.
모델을 양자화하는 데는 전부 세 가지의 접근법 및 작업방식이 있습니다. 학습 후 동적 양자화, 학습 후 정적 양자화, 그리고 양자화를 고려한 학습이 있습니다. 하지만 사용하려는 모델이 이미 양자화된 버전이 있다면, 위의 세 가지 방식을 거치지 않고 그 버전을 바로 사용하면 됩니다. 예를 들어, `torchvision` 라이브러리에는 이미 MobileNet v2, ResNet 18, ResNet 50, Inception v3, GoogleNet을 포함한 모델의 양자화된 버전이 존재합니다. 따라서 비록 단순한 작업이겠지만, 이미 존재하는 모델 사용을 또 다른 작업 방식 중 하나로 포함하려 합니다.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

학습 후 동적 양자화, 학습 후 정적 양자화, 그리고 양자화를 고려한 학습이 있습니다. -> 학습 후 동적 양자화(post training dynamic quantization), 학습 후 정적 양자화(post training static quantization), 그리고 양자화를 고려한 학습(quantization aware training)이 있습니다.
번역된 단어만으로는 정확한 의미를 알기 어려울 수 있을 것 같아 괄호 속에 원문을 넣는게 좋을 것 같습니다!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

넵 감사합니다! 첫 언급 이후 아래 계속 언급될 때는 영어를 안적어줘도 괜찮겠죠?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

첫 언급 이후에는 필요에 따라 적어도 되고 안 적어도 상관없습니다. 다만 제목인 경우에는 적어주는게 좋을 것 같습니다.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

넵 의견 정말 감사드립니다!


To apply Dynamic Quantization, which converts all the weights in a model from 32-bit floating numbers to 8-bit integers but doesn't convert the activations to int8 till just before performing the computation on the activations, simply call `torch.quantization.quantize_dynamic`:
동적 양자화를 적용하면, 모델의 모든 가중치는 32-비트 크기의 실수 자료형에서 8-비트 크기의 정수 자료형으로 전환되지만, 활성화에 대한 계산을 진행하기 직전까지는 활성 함수는 8-비트 정수형으로 전환하지 않게 됩니다. 동적 양자화를 적용하려면, `torch.quantization.quantize_dynamic`\을 사용하면 됩니다.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

32비트, 8비트 위와 동일합니다.


.. warning:: An important limitation of Dynamic Quantization, while it is the easiest workflow if you do not have a pre-trained quantized model ready for use, is that it currently only supports `nn.Linear` and `nn.LSTM` in `qconfig_spec`, meaning that you will have to use Static Quantization or Quantization Aware Training, to be discussed later, to quantize other modules such as `nn.Conv2d`.
.. warning:: 동적 양자화는 사전 학습된 양자화 적용 모델이 준비되지 않았을 때 사용하기 가장 쉬운 방식이지만, 이 방식의 주요 한계는 `qconfig_spec` 옵션이 현재는 `nn.Linear`\과 `nn.LSTM`\만 지원한다는 것입니다. 이는 당신이 `nn.Conv2d`\같은 다른 모듈을 양자화할 때, 나중에 논의될 정적 양자화나 양자화를 고려한 학습을 사용해야 한다는 걸 의미합니다.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

백 슬래시는 일부러 넣으신건가요?

Copy link
Contributor Author

@hjvision96 hjvision96 Sep 5, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

' 표시 다음에 띄어쓰기 없이 한글이 올 때는 백슬래시를 넣어야 make html-noplot 했을 때 오류가 안생기더라구요!
백슬래시를 넣어서 오류를 안생기게 하냐 vs. 그냥 '표시 뒤에 한글이 오면 띄어 쓰냐
중에서 전자를 선택한거긴 한데, 혹시 후자가 맞는걸까요?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

백슬래시를 넣어서 이스케이핑 할 수 있지만 대부분의 문서들이 한 칸 띄어쓰기로 적혀 있기에 통일하는게 좋을 것 같습니다.
꼭 붙여야 하는 경우에는 \ 를 여러개 안 쓰고 맨 뒤에 하나만 붙여도 오류 안 뜰겁니다.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

아하 대부분의 경우 그렇군요 감사합니다!


This method converts both the weights and the activations to 8-bit integers beforehand so there won't be on-the-fly conversion on the activations during the inference, as the dynamic quantization does, hence improving the performance significantly.
이 방식은 모델의 가중치와 활성 함수 모두를 8-비트 크기의 정수 자료형으로 사전에 바꾸기 때문에, 동적 양자화처럼 추론 과정 중에 활성 함수를 전환하지는 않습니다. 따라서 이 방식은 성능이 상당히 높습니다.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

8비트, 위와 내용 동일

@hjvision96 hjvision96 requested review from YunjinJo, terri1102 and updaun and removed request for YunjinJo and terri1102 September 6, 2022 12:40
Copy link
Member

@hyoyoung hyoyoung left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

긴 글 번역하느라 수고하셨습니다

몇가지 제안을 드립니다


This recipe demonstrates how to quantize a PyTorch model so it can run with reduced size and faster inference speed with about the same accuracy as the original model. Quantization can be applied to both server and mobile model deployment, but it can be especially important or even critical on mobile, because a non-quantized model's size may exceed the limit that an iOS or Android app allows for, cause the deployment or OTA update to take too much time, and make the inference too slow for a good user experience.
이 레시피는 Pytorch 모델을 양자화하는 방법을 설명합니다. 양자화된 모델은 원본 모델과 거의 같은 정확도를 내면서, 사이즈가 줄어들고 추론 속도가 빨라집니다. 양자화 작업은 서버 모델과 모바일 모델 배포에 모두 적용될 수 있지만, 모바일 환경에서 특히 중요하고 매우 필요합니다. 그 이유는 양자화를 적용하지 않은 모델의 크기가 IOS나 Android 앱이 허용하는 크기 한도를 초과하고, 그로 인해 모델의 배포나 OTA 업데이트가 너무 오래 걸리며, 또한 추론 속도가 너무 느려서 사용자의 쾌적함을 방해하기 때문입니다.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IOS -> iOS


There are overall three approaches or workflows to quantize a model: post training dynamic quantization, post training static quantization, and quantization aware training. But if the model you want to use already has a quantized version, you can use it directly without going through any of the three workflows above. For example, the `torchvision` library already includes quantized versions for models MobileNet v2, ResNet 18, ResNet 50, Inception v3, GoogleNet, among others. So we will make the last approach another workflow, albeit a simple one.
모델을 양자화하는 데는 전부 세 가지의 접근법 및 작업방식이 있습니다. 학습 후 동적 양자화(post training dynamic quantization), 학습 후 정적 양자화(post training static quantization), 그리고 양자화를 고려한 학습(quantization awqre training)이 있습니다. 하지만 사용하려는 모델이 이미 양자화된 버전이 있다면, 위의 세 가지 방식을 거치지 않고 그 버전을 바로 사용하면 됩니다. 예를 들어, `torchvision` 라이브러리에는 이미 MobileNet v2, ResNet 18, ResNet 50, Inception v3, GoogleNet을 포함한 모델의 양자화된 버전이 존재합니다. 따라서 비록 단순한 작업이겠지만, 사전 학습 및 양자화된 모델 사용(use pretrained quantized model)을 또 다른 작업 방식 중 하나로 포함하려 합니다.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

quantization awqre training -> quantization aware training


.. warning:: An important limitation of Dynamic Quantization, while it is the easiest workflow if you do not have a pre-trained quantized model ready for use, is that it currently only supports `nn.Linear` and `nn.LSTM` in `qconfig_spec`, meaning that you will have to use Static Quantization or Quantization Aware Training, to be discussed later, to quantize other modules such as `nn.Conv2d`.
.. warning:: 동적 양자화는 사전 학습된 양자화 적용 모델이 준비되지 않았을 때 사용하기 가장 쉬운 방식이지만, 이 방식의 주요 한계는 `qconfig_spec` 옵션이 현재는 `nn.Linear` `nn.LSTM` 만 지원한다는 것입니다. 이는 당신이 `nn.Conv2d` 같은 다른 모듈을 양자화할 때, 나중에 논의될 정적 양자화나 양자화를 고려한 학습을 사용해야 한다는 걸 의미합니다.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'당신'은 제거 해도 될듯 합니다


This method converts both the weights and the activations to 8-bit integers beforehand so there won't be on-the-fly conversion on the activations during the inference, as the dynamic quantization does, hence improving the performance significantly.
이 방식은 모델의 가중치와 활성 함수 모두를 8비트 크기의 정수 자료형으로 사전에 바꾸기 때문에, 동적 양자화처럼 추론 과정 중에 활성 함수를 전환하지는 않습니다. 따라서 이 방식은 성능이 상당히 높습니다.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

성능이 상당히 높다는 얘기는 고성능입니다라고 하거나
성능이 뛰어나다고 하는게 조금 더 읽기 편할 듯 합니다.

@hjvision96 hjvision96 requested review from hyoyoung and removed request for updaun September 10, 2022 14:27
Copy link
Member

@hyoyoung hyoyoung left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good

@hyoyoung hyoyoung merged commit a3819d6 into PyTorchKorea:master Sep 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
컨트리뷰톤 오픈소스 컨트리뷰톤 관련 이슈/PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants