Skip to content

Commit d74162b

Browse files
authored
prototype_source/tracing_based_selective_build.rst 번역 (B조) (#565)
* Translate prototype_source/tracing_based_selective_build.rst
1 parent 75637d5 commit d74162b

1 file changed

Lines changed: 45 additions & 45 deletions

File tree

Lines changed: 45 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,25 @@
1-
(prototype) Tracing-based Selective Build Mobile Interpreter in Android and iOS
2-
===============================================================================
1+
(prototype) 추적-기반 선택적 빌드 모바일 Android, iOS 인터프리터
2+
==============================================================
33

44

5-
*Author*: Chen Lai <https://github.com/cccclai>, Dhruv Matani <https://github.com/dhruvbird>
5+
*저자*: Chen Lai <https://github.com/cccclai>, Dhruv Matani <https://github.com/dhruvbird>
66

7-
.. warning::
8-
Tracing-based selective build a prototype feature to minimize library size. Since the traced result relies on the model input and traced environment, if the tracer runs in a different environment than mobile interpreter, the operator list might be different from the actual used operator list and missing operators error might raise.
7+
*역자*: Lee Jong Bub <https://github.com/bub3690>
8+
9+
10+
.. 경고::
11+
추적-기반 선택적 빌드는 라이브러리 사이즈를 줄이기 위한 프로토타입 기능입니다. 추적된 결과는 모델 입력과 추적된 환경에 의존합니다. 따라서, 만약 추적기가 모바일 인터프리터가 아닌 다른 환경에서 실행되면, 연산자 리스트가 실제 사용된 연산자 리스트와 다를 수 있고 빠진 연산자들이 오류를 발생시킬 수 있습니다.
912

1013
Introduction
1114
------------
1215

16+
이 튜토리얼은 모바일 인터프리터 사이즈를 더욱 더 최소화하기 위해, 모바일 인터프리터 빌드를 커스터마이즈하는 새로운 방법을 소개합니다. 컴파일된 이진 파일에 포함되는 연산자들을 목표 모델에 실제로 필요로 하는 집합만큼으로 제한합니다. 파이토치의 모바일 배포의 이진 파일 사이즈를 줄이는 기술입니다. 추적 기반 선택적 빌드는 모델을 특정 대표 입력값들과 함께 동작시킵니다, 그리고 어떤 연산자들이 호출되었는지 기록합니다. 그러면 빌드는 그 연산자들만 포함하게 됩니다.
1317

14-
This tutorial introduces a new way to custom build mobile interpreter to further optimize mobile interpreter size. It restricts the set of operators included in the compiled binary to only the set of operators actually needed by target models. It is a technique to reduce the binary size of PyTorch for mobile deployments. Tracing Based Selective Build runs a model with specific representative inputs, and records which operators were called. The build then includes just those operators.
1518

1619

17-
Following are the processes to use tracing-based selective approach to build a custom mobile interpreter.
20+
다음은 추적-기반 선택적 방법으로 커스텀 모바일 인터프리터를 제작하는 과정들입니다.
1821

19-
1. *Prepare model with bundled input*
22+
1. *묶인 입력과 모델을 준비합니다*
2023

2124
.. code:: python
2225
@@ -28,54 +31,54 @@ Following are the processes to use tracing-based selective approach to build a c
2831
from PIL import Image
2932
from torchvision import transforms
3033
31-
# Step 1. Get the model
34+
# 단계 1. 모델을 가져옵니다.
3235
model = torch.hub.load('pytorch/vision:v0.7.0', 'deeplabv3_resnet50', pretrained=True)
3336
model.eval()
3437
3538
scripted_module = torch.jit.script(model)
36-
# Export full jit version model (not compatible lite interpreter), leave it here for comparison
39+
# 비교를 위해, jit 전체 버전 모델을 출력합니다.(가벼운 인터프리터와는 호환되지 않습니다.)
3740
scripted_module.save("deeplabv3_scripted.pt")
38-
# Export lite interpreter version model (compatible with lite interpreter)
39-
# path = "<base directory where models are stored>"
41+
# 가벼운 인터프리터 버전 모델을 출력합니다.(가벼운 인터프리터와 호환됩니다.)
42+
# path = "<모델이 저장된 기본 위치>"
4043
4144
scripted_module._save_for_lite_interpreter(f"${path}/deeplabv3_scripted.ptl")
4245
4346
model_file = f"${path}/deeplabv3_scripted.ptl"
4447
45-
# Step 2. Prepare inputs for the model
48+
# 단계 2. 모델에 사용될 이미지를 준비합니다.
4649
input_image_1 = Image.open(f"${path}/dog.jpg")
4750
preprocess = transforms.Compose([
4851
transforms.ToTensor(),
4952
transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]),
5053
])
5154
5255
input_tensor_1 = preprocess(input_image_1)
53-
input_batch_1 = input_tensor_1.unsqueeze(0) # create a mini-batch as expected by the model
56+
input_batch_1 = input_tensor_1.unsqueeze(0) # 모델에 사용될 미니 배치를 제작합니다.
5457
5558
scripted_module = torch.jit.load(model_file)
56-
scripted_module.forward(input_batch_1) # optional, to validate the model can run with the input_batch_1
59+
scripted_module.forward(input_batch_1) # 선택적으로, 모델을 검증하기 위해 input_batch_1과 함께 작동시킵니다.
5760
5861
input_image_2 = Image.open(f"${path}/deeplab.jpg")
5962
input_tensor_2 = preprocess(input_image_2)
60-
input_batch_2 = input_tensor_2.unsqueeze(0) # create a mini-batch as expected by the model
63+
input_batch_2 = input_tensor_2.unsqueeze(0) # 모델에 사용될 미니 배치를 제작합니다.
6164
6265
scripted_module = torch.jit.load(model_file)
63-
scripted_module.forward(input_batch_2) # optional, to validate the model can run with the input_batch_2
66+
scripted_module.forward(input_batch_2) # 선택적으로, 모델을 검증하기 위해 input_batch_2과 함께 작동시킵니다.
6467
65-
# Step 3. Bundle the model with the prepared input from step2. Can bundle as many input as possible.
68+
# 단계 3. 모델과 단계2에서 준비된 입력을 같이 묶어줍니다. 가능한 많은 입력을 묶어줍니다.
6669
bundled_model_input = [
6770
(torch.utils.bundled_inputs.bundle_large_tensor(input_batch_1), ),
6871
(torch.utils.bundled_inputs.bundle_large_tensor(input_batch_2), )]
6972
bundled_model = torch.utils.bundled_inputs.bundle_inputs(scripted_module, bundled_model_input)
7073
bundled_model._save_for_lite_interpreter(f"${path}/deeplabv3_scripted_with_bundled_input.ptl")
7174
72-
2. Build tracer
75+
2. 추적기를 제작합니다.
7376

7477
.. code:: shell
7578
7679
MACOSX_DEPLOYMENT_TARGET=10.9 CC=clang CXX=clang++ MAX_JOBS=16 TRACING_BASED=1 python setup.py develop
7780
78-
3. Run tracer with the model with bundled input
81+
3. 추적기와 모델을 입력과 함께 동작시킵니다.
7982

8083
.. code:: shell
8184
@@ -86,22 +89,22 @@ Following are the processes to use tracing-based selective approach to build a c
8689
Android
8790
-------
8891

89-
Get the Image Segmentation demo app in Android: https://github.com/pytorch/android-demo-app/tree/master/ImageSegmentation
92+
이미지 영역 분할 Android 데모 App을 가져옵니다 : https://github.com/pytorch/android-demo-app/tree/master/ImageSegmentation
9093

91-
1. **Tracing-based build libtorch lite for android**: Build libtorch for android for all 4 android abis (``armeabi-v7a``, ``arm64-v8a``, ``x86``, ``x86_64``) by running
94+
1. **Android를 위한 libtorch lite 추적-기반 빌드**: 모든 4 가지 Android abis(``armeabi-v7a``, ``arm64-v8a``, ``x86``, ``x86_64``)를 대상으로 libtorch를 빌드합니다.
9295

9396
.. code-block:: bash
9497
9598
SELECTED_OP_LIST=${path}/deeplabv3_scripted.yaml TRACING_BASED=1 ./scripts/build_pytorch_android.sh
9699
97-
if it will be tested on Pixel 4 emulator with ``x86``, use cmd ``BUILD_LITE_INTERPRETER=1 ./scripts/build_pytorch_android.sh x86`` to specify abi to save build time.
100+
만약 ``x86`` 의 Pixel 4 emulator에서 테스트 된다면, cmd 에서 ``BUILD_LITE_INTERPRETER=1 ./scripts/build_pytorch_android.sh x86`` 사용하여, 빌드 시간을 절약하기 위해 abi를 명시해줍니다.
98101

99102
.. code-block:: bash
100103
101104
SELECTED_OP_LIST=${path}/deeplabv3_scripted.yaml TRACING_BASED=1 ./scripts/build_pytorch_android.sh x86
102105
103106
104-
After the build finish, it will show the library path:
107+
빌드가 끝난 후, 라이브러리 경로를 보여줄 것입니다 :
105108

106109
.. code-block:: bash
107110
@@ -112,7 +115,7 @@ After the build finish, it will show the library path:
112115
-rw-r--r-- 1 chenlai staff 13M Feb 11 11:48 /Users/chenlai/pytorch/android/pytorch_android/build/outputs/aar/pytorch_android-release.aar
113116
-rw-r--r-- 1 chenlai staff 36K Feb 9 16:45 /Users/chenlai/pytorch/android/pytorch_android_torchvision/build/outputs/aar/pytorch_android_torchvision-release.aar
114117
115-
2. **Use the PyTorch Android libraries built from source in the ImageSegmentation app**: Create a folder `libs` in the path, the path from repository root will be `ImageSegmentation/app/libs`. Copy `pytorch_android-release` to the path ``ImageSegmentation/app/libs/pytorch_android-release.aar``. Copy `pytorch_android_torchvision` (downloaded from `Pytorch Android Torchvision Nightly <https://oss.sonatype.org/#nexus-search;quick~torchvision_android/>`_) to the path ``ImageSegmentation/app/libs/pytorch_android_torchvision.aar``. Update the `dependencies` part of ``ImageSegmentation/app/build.gradle`` to
118+
2. **이미지 영역 분할 App 소스에서 빌드된 Pytorch Android 라이브러리를 사용합니다**: 경로에 `libs` 폴더를 만들고, 경로는 root 저장소로부터 `ImageSegmentation/app/libs` 가 됩니다. `pytorch_android-release` 를 경로 ``ImageSegmentation/app/libs/pytorch_android-release.aar`` 에 복사합니다. `pytorch_android_torchvision` (다운로드 : `Pytorch Android Torchvision Nightly <https://oss.sonatype.org/#nexus-search;quick~torchvision_android/>`_)를 경로 ``ImageSegmentation/app/libs/pytorch_android_torchvision.aar`` 에 복사합니다. ``ImageSegmentation/app/build.gradle`` 에서 `dependencies` 부분을 다음 코드와 같이 수정합니다 :
116119

117120
.. code:: gradle
118121
@@ -131,7 +134,7 @@ After the build finish, it will show the library path:
131134
implementation 'com.facebook.fbjni:fbjni-java-only:0.0.3'
132135
}
133136
134-
Update `all projects` part in ``ImageSegmentation/build.gradle`` to
137+
``ImageSegmentation/build.gradle`` 에서 `all projects` 파트를 다음 코드와 같이 수정합니다.
135138

136139

137140
.. code:: gradle
@@ -146,56 +149,53 @@ Update `all projects` part in ``ImageSegmentation/build.gradle`` to
146149
}
147150
}
148151
149-
150-
3. **Test app**: Build and run the `ImageSegmentation` app in Android Studio
152+
3. **App 테스트하기**: Android 스튜디오에서 `ImageSegmentation` App을 빌드하고 실행합니다.
151153

152154

153155
iOS
154156
---
155157

156-
Get ImageSegmentation demo app in iOS: https://github.com/pytorch/ios-demo-app/tree/master/ImageSegmentation
158+
이미지 영역 분할 iOS 데모 App을 가져옵니다: https://github.com/pytorch/ios-demo-app/tree/master/ImageSegmentation
157159

158160

159-
1. **Build libtorch lite for iOS**:
161+
1. **libtorch lite iOS 빌드합니다**:
160162

161163
.. code-block:: bash
162164
163165
SELECTED_OP_LIST=${path}/deeplabv3_scripted.yaml TRACING_BASED=1 IOS_PLATFORM=SIMULATOR ./scripts/build_ios.sh
164166
165167
166-
2. **Remove Cocoapods from the project** (this step is only needed if you ran `pod install`):
168+
2. **프로젝트에서 Cocoapods 제거합니다** (이 과정은 `pod install` 을 사용했을 때만 필요합니다):
167169

168170

169171
.. code-block:: bash
170172
171173
pod deintegrate
172174
173175
174-
3. **Link ImageSegmentation demo app with the custom built library**:
176+
3. **이미지 영역 분할 데모 App을 커스텀 라이브러리들과 링크해줍니다**:
175177

176-
Open your project in XCode, go to your project Target’s **Build Phases - Link Binaries With Libraries**, click the **+** sign and add all the library files located in `build_ios/install/lib`. Navigate to the project **Build Settings**, set the value **Header Search Paths** to `build_ios/install/include` and **Library Search Paths** to `build_ios/install/lib`.
177-
In the build settings, search for **other linker flags**. Add a custom linker flag below `-all_load`.
178-
Finally, disable bitcode for your target by selecting the Build Settings, searching for Enable Bitcode, and set the value to **No**.
178+
Xcode에서 프로젝트를 열고, 목표 프로젝트의 **Build Phases - Link Binaries With Libraries** 로 가서, **+** 기호를 클릭하고 `build_ios/install/lib` 에 위치한 모든 라이브러리 파일들을 추가합니다. 프로젝트 **Build Settings** 로 이동하여, **Header Search Paths** 에서 값을 `build_ios/install/include` 로 값을 설정하고 **Library Search Paths** `build_ios/install/lib` 로 값을 설정합니다.
179+
build settings에서, **other linker flags** 를 검색합니다. `-all_load` 아래에 커스텀 링커 플래그를 추가합니다.
180+
마지막으로, 목표를 위해 Build Settings에서 bitcode를 사용하지 못하게 선택해야 합니다, Enable Bitcode를 검색하여, **No** 값으로 설정합니다.
179181

180-
181-
4. **Build and test the app in Xcode.**
182+
4. **Xcode에서 App을 빌드하고 테스트합니다**
182183

183184

184185

185186
Conclusion
186187
----------
187188

188-
In this tutorial, we demonstrated a new way to custom build PyTorch's efficient mobile interpreter - tracing-based selective build, in an Android and iOS app.
189-
190-
We walked through an Image Segmentation example to show how to bundle inputs to a model, generated operator list by tracing the model with bundled input, and build a custom torch library from source with the operator list from tracing result.
189+
이 튜토리얼에서는, Android와 iOS App에서 효율적인 Pyotorch 모바일 인터프리터를 커스텀 빌드하는 새로운 방법인 추적-기반 선택적 빌드를 시연했습니다.
191190

192-
The custom build is still under development, and we will continue improving its size in the future. Note, however, that the APIs are subject to change in future versions.
191+
이미지 영역 분할 예제를 수행하며 모델에 들어갈 입력을 어떻게 묶는지 보여주었고, 묶인 입력과 모델을 추적함으로써 연산자 리스트를 생성했고, 추적된 결과의 연산자 리스트와 소스로 커스텀 torch 라이브러리를 빌드했습니다.
193192

194-
Thanks for reading! As always, we welcome any feedback, so please create an issue here <https://github.com/pytorch/pytorch/issues>`.
193+
커스텀 빌드는 여전히 개발중이고, 앞으로 미래에도 계속 사이즈를 개선시킬 것입니다. 그러나, API들은 미래 version에 따라 종속된다는 것을 주의하세요.
195194

196-
Learn More
195+
읽어주셔서 감사합니다! 언제나, 어떤 피드백이든 환영합니다. `<https://github.com/pytorch/pytorch/issues>`_ 에 이슈를 생성해주세요.
197196

197+
더 배우기
198198

199-
- To learn more about PyTorch Mobile, please refer to PyTorch Mobile Home Page <https://pytorch.org/mobile/home/>
199+
- Pytorch 모바일에 대해 더 배우기 위해서는, Pytorch 모바일 홈페이지 `<https://pytorch.org/mobile/home/>`_ 를 참조해주세요.
200200

201-
* To learn more about Image Segmentation, please refer to the Image Segmentation DeepLabV3 on Android Recipe <https://tutorials.pytorch.kr/beginner/deeplabv3_on_android.html>_
201+
* 이미지 영역 분할에 대해 더 배우려면, Andorid Recipe의 Image Segmentation DeepLabV3를 참조해주세요 `<https://tutorials.pytorch.kr/beginner/deeplabv3_on_android.html>`_

0 commit comments

Comments
 (0)