Skip to content

feat) optimization kr translation #1

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 14 commits into from
May 19, 2023
Merged

feat) optimization kr translation #1

merged 14 commits into from
May 19, 2023

Conversation

tjdtnsu
Copy link
Member

@tjdtnsu tjdtnsu commented Jan 21, 2023

No description provided.

Copy link
Member

@seriousran seriousran left a comment

Choose a reason for hiding this comment

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

리뷰 남깁니다!

| cuDNN auto-tuner | 9.37s | x1.01 |
| fp16 | 3.61s | x2.63 |
| 채널 마지막 형식 | 3.30s | x2.88 |
| 추적을 수행한 UNet | 3.21s | x2.96 |
Copy link
Member

Choose a reason for hiding this comment

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

추적을 번역할 지 논의해보면 좋을 것 같아요


# 메모리와 속도

메모리 또는 속도에 대해 🤗 Diffusers *추론*을 최적화하기 위한 몇 가지 기술과 아이디어를 제시합니다. 일반적으로, 메모리 효율적인 어텐션을 위해 [xFormers](https://github.com/facebookresearch/xformers) 사용을 추천하기 때문에, 추천하는 [설치 방법](xformers)을 보세요.
Copy link
Member

Choose a reason for hiding this comment

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

"xformer 설치 방법을 보시고 설치해 보세요."라고 하는 게 의미가 명확할 것 같습니다.

| 메모리 효율적인 어텐션 | 2.63s | x3.61 |

<em>
NVIDIA TITAN RTX에서 50 DDIM 단계의 "a photo of an astronaut riding a horse on mars" 프롬프트로 512x512 크기의 단일 이미지를 생성하였습니다.
Copy link
Member

Choose a reason for hiding this comment

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

50 DDIM 단계 -> DDIM 50 단계인데, step을 단계로 번역할지 셋이서 얘기해보고 통일해야할 것 같아요.

Choose a reason for hiding this comment

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

위 도표는 "a photo of an astronaut riding a horse on mars"라는 프롬프트로 512x512 크기의 단일 이미지를 생성했을 때의 결과를 정리한 표입니다. 해당 테스트에서 GPU는 NVIDIA TITAN RTX를 사용했고, DDIM 스텝은 50으로 설정했습니다.

이렇게 번역해봐도 좋을 것 같습니다. 저의 번역에서는 DDIM step을 마치 하나의 옵션처럼 표현했는데, 혹시 제가 디퓨전 모델에 대한 지식의 부족으로 인한 오역을 범한 건 아닌지 걱정되는 바입니다.

Choose a reason for hiding this comment

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

그리고 step은 스텝으로 번역하는 게 좋을 것 같습니다. method를 메서드라고 번역하듯이요.


## cuDNN auto-tuner 활성화하기

[NVIDIA cuDNN](https://developer.nvidia.com/cudnn)은 컨벌루션을 계산하는 많은 알고리즘을 지원합니다. Autotuner는 짧은 벤치마크를 실행하고 주어진 입력 크기에 대해 주어진 하드웨어에서 최고의 성능을 가진 커널을 선택합니다.
Copy link
Member

Choose a reason for hiding this comment

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

"컨볼루션"으로 통일할까요?

Copy link
Member

@howsmyanimeprofilepicture howsmyanimeprofilepicture Feb 4, 2023

Choose a reason for hiding this comment

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

@seriousran 좋습니다.


### fp32 대신 tf32 사용하기 (Ampere 및 이후 CUDA 장치들에서)

Ampere 및 이후 CUDA 장치에서 행렬 곱셈 및 컨볼루션은 TensorFloat32(TF32) 모드를 사용하여 더 빠르지만 약간 덜 정확할 수 있습니다. 기본적으로 PyTorch는 컨볼루션에 대해 TF32 모드를 활성화하지만 행렬 곱셈은 활성화하지 않습니다. 네트워크에 완전한 float32 정밀도가 필요한 경우가 아니면 행렬 곱셈에 대해서도 이 설정을 활성화하는 것이 좋습니다. 이는 일반적으로 무시할 수 있는 수치의 정확도 손실로 계산 속도를 크게 높일 수 있습니다. 그것에 대해 [여기](https://huggingface.co/docs/transformers/v4.18.0/en/performance#tf32)서 더 읽을 수 있습니다. 추론하기 전에 다음을 추가하기만 하면 됩니다:
Copy link
Member

Choose a reason for hiding this comment

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

행렬 곱셈 -> 행렬곱
으로 통일할까요?

"그것에 대해 [여기]서 더 읽을 수 있습니다." "그것에 대한 자세한 내용은 [여기]서 더 살펴보실 수 있습니다." 의 느낌이 좋지 않을까요?

Choose a reason for hiding this comment

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

Ampere를 비롯한 최근 CUDA 장치에서는 행렬곱과 컨볼루션 연산에 TensorFloat32(TF32) 모드를 사용하고 있습니다. 이를 통해 약간 덜 정확하더라도 더 빠르게 해당 연산들을 처리할 수 있습니다.

첫번째 문장을 위와 같이 번역해보면 어떨까요?

text_encoder=accelerator.unwrap_model(text_encoder),
)

# 추론을 수행하거나 저장하거나, 허브에 푸시합니다.
Copy link
Member

Choose a reason for hiding this comment

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

푸시, 푸쉬 통일이 핑요할 것 같습니다.


<Tip warning={true}>

text-to-image 미세 조정 스크립트는 실험적입니다. 과적합하기 쉽고 치명적인 망각과 같은 문제에 부딪히기 쉽습니다. 자체 데이터셋에서 최상의 결과를 얻으려면 다양한 하이퍼파라미터를 탐색하는 것이 좋습니다.
Copy link
Member

Choose a reason for hiding this comment

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

위에서 텍스트 이미지 생성 이라고 봤던 것 같은데 text-to-image 는 번역 안하고 유지하는 기 좋을 것 같습니다.

accelerate config
```

가중치를 다운로드하거나 사용하기 전에 모델 라이선스에 동의해야 합니다. 이 예시에서는 모델 버전 `v1-4`를 사용하므로, [이 링크](https://huggingface.co/CompVis/stable-diffusion-v1-4)를 방문하여 라이선스를 읽고 동의하면 확인란을 선택하십시오.
Copy link
Member

Choose a reason for hiding this comment

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

라이선스, 라이센스 통일 논의 필요

accelerate config
```

가중치를 다운로드하거나 사용하기 전에 모델 라이선스에 동의해야 합니다. 이 예시에서는 모델 버전 `v1-4`를 사용하므로, [이 링크](https://huggingface.co/CompVis/stable-diffusion-v1-4)를 방문하여 라이선스를 읽고 동의하면 확인란을 선택하십시오.
Copy link
Member

Choose a reason for hiding this comment

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

요거 없어진 것 같은데 확인 필요합니다.


### 미세 조정 예시

다음 스크립트는 Hugging Face Hub에서 사용할 수 있는 [Justin Pinkneys이 캡션한 Pokemon 데이터셋](https://huggingface.co/datasets/lambdalabs/pokemon-blip-captions)를 사용하여 미세 조정 실행을 시작합니다.
Copy link
Member

Choose a reason for hiding this comment

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

미세조정 실행 -> 미세조정 만으로도 의미가 충분하지 않을까요?

미세조정 띄어쓰기 통일 논의 필요

Copy link
Member

@howsmyanimeprofilepicture howsmyanimeprofilepicture left a comment

Choose a reason for hiding this comment

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

전체적으로 지나치게 기계적인 번역들을 좀 더 직관적으로 풀어볼 필요가 있을 것 같습니다. 우선 용어들부터 통일할까요?


### fp32 대신 tf32 사용하기 (Ampere 및 이후 CUDA 장치들에서)

Ampere 및 이후 CUDA 장치에서 행렬 곱셈 및 컨볼루션은 TensorFloat32(TF32) 모드를 사용하여 더 빠르지만 약간 덜 정확할 수 있습니다. 기본적으로 PyTorch는 컨볼루션에 대해 TF32 모드를 활성화하지만 행렬 곱셈은 활성화하지 않습니다. 네트워크에 완전한 float32 정밀도가 필요한 경우가 아니면 행렬 곱셈에 대해서도 이 설정을 활성화하는 것이 좋습니다. 이는 일반적으로 무시할 수 있는 수치의 정확도 손실로 계산 속도를 크게 높일 수 있습니다. 그것에 대해 [여기](https://huggingface.co/docs/transformers/v4.18.0/en/performance#tf32)서 더 읽을 수 있습니다. 추론하기 전에 다음을 추가하기만 하면 됩니다:

Choose a reason for hiding this comment

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

Ampere를 비롯한 최근 CUDA 장치에서는 행렬곱과 컨볼루션 연산에 TensorFloat32(TF32) 모드를 사용하고 있습니다. 이를 통해 약간 덜 정확하더라도 더 빠르게 해당 연산들을 처리할 수 있습니다.

첫번째 문장을 위와 같이 번역해보면 어떨까요?

추가 메모리 절약을 위해, 한 번에 모두 계산하는 대신 단계적으로 계산을 수행하는 슬라이스 버전의 어텐션을 사용할 수 있습니다.

<Tip>
어텐션 슬라이싱은 모델이 하나 이상의 어텐션 헤드를 사용하는 한 배치 크기가 1인 경우에도 유용합니다. 하나 이상의 어텐션 헤드가 있는 경우 *QK^T* 어텐션 매트릭스는 상당한 양의 메모리를 절약할 수 있는 각 헤드에 대해 순차적으로 계산될 수 있습니다.

Choose a reason for hiding this comment

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

모델이 하나 이상의 어텐션 헤드를 사용하는 한, 어텐션 슬라이싱은 배치 사이즈가 단 1인 경우에도 유용합니다. 하나 이상의 어텐션 헤드가 있다면, 각 헤드에 대한 QK^T 어텐션 매트릭스를 순차적으로 연산함으로써 상당한 양의 메모리를 절약할 수 있습니다.

라고 번역해보아도 좋을 것 같습니다!

추가 메모리 절약을 위해, 한 번에 모두 계산하는 대신 단계적으로 계산을 수행하는 슬라이스 버전의 어텐션을 사용할 수 있습니다.

<Tip>
어텐션 슬라이싱은 모델이 하나 이상의 어텐션 헤드를 사용하는 한 배치 크기가 1인 경우에도 유용합니다. 하나 이상의 어텐션 헤드가 있는 경우 *QK^T* 어텐션 매트릭스는 상당한 양의 메모리를 절약할 수 있는 각 헤드에 대해 순차적으로 계산될 수 있습니다.

Choose a reason for hiding this comment

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

Sliced attention도 어떻게 번역하면 좋을지 고민해봐야 할 거 같습니다.

image = pipe(prompt).images[0]
```

There's a small performance penalty of about 10% slower inference times, but this method allows you to use Stable Diffusion in as little as 3.2 GB of VRAM!

Choose a reason for hiding this comment

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

아래 번역된 문장이 있는 걸로 보아, 이건 지우는 걸 깜박하신 거 같네요.

images = pipe([prompt] * 32).images
```

다중 이미지 배치에서 VAE 디코드가 약간의 성능 향상을 볼 수 있습니다. 단일 이미지 배치에서는 성능 영향이 없어야 합니다.

Choose a reason for hiding this comment

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

오독(misreading)의 가능성을 최소화 하고자 한국어와 영어를 함께 표기하는 것도 고려해 봐야할 것 같습니다. e.g., **다중 이미지 배치(multi-image batches)**라고 표기하는 것처럼요.

다중 이미지 배치에서 VAE 디코드가 약간의 성능 향상을 볼 수 있습니다. 단일 이미지 배치에서는 성능 영향이 없어야 합니다.


## 메모리 절약을 위해 가속 기능을 사용하여 CPU로 오프로드

Choose a reason for hiding this comment

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

"메모리 절약을 위한 CPU 오프로딩"으로 번역해도 좋을 것 같아요.

image = pipe(prompt).images[0]
```

**참고**: 'enable_sequential_cpu_offload()'를 사용할 때, 미리 파이프라인을 CUDA로 이동하지 **않는** 것이 중요합니다. 그렇지 않으면 메모리 소비의 이득이 최소화됩니다. 더 많은 정보를 위해 [이 이슈](https://github.com/huggingface/diffusers/issues/1934)를 보세요.

Choose a reason for hiding this comment

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

그렇지 않으면 CPU 오프로딩을 통해 얻는 메모리 상의 이점이 최소화되기 때문입니다. 해당 이슈를 참고해보세요.

이렇게 번역해봐도 좋을 것 같습니다 :D


**참고**: 'enable_sequential_cpu_offload()'를 사용할 때, 미리 파이프라인을 CUDA로 이동하지 **않는** 것이 중요합니다. 그렇지 않으면 메모리 소비의 이득이 최소화됩니다. 더 많은 정보를 위해 [이 이슈](https://github.com/huggingface/diffusers/issues/1934)를 보세요.

## 채널 마지막 메모리 형식 사용하기

Choose a reason for hiding this comment

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

(Channels Last)라는 원어를 함께 표기하면 더 좋을 것 같습니다 :D

- [`GaudiStableDiffusionPipeline`](https://huggingface.co/docs/optimum/habana/package_reference/stable_diffusion_pipeline)이 포함된 파이프라인. 이 파이프라인은 *텍스트-이미지 생성*을 지원합니다.
- [`GaudiDDIMScheduler`](https://huggingface.co/docs/optimum/habana/package_reference/stable_diffusion_pipeline#optimum.habana.diffusers.GaudiDDIMScheduler)이 포함된 스케줄러. 이 스케줄러는 Habana Gaudi에 최적화되어 있습니다.

파이프라인을 초기화할 때, HPU에 배포하기 위해 `use_habana=True`를 지정해야 합니다.

Choose a reason for hiding this comment

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

HPU를 통해 구동하기 위해

이렇게 번역하면 어떨까요? HPU까 일종의 프로세서 같은 것 같은데 (혹시 잘못 알고 있다면 말씀해주세요.), "HPU에 배포하기 위해"라는 표현은 마치 HPU가 일종의 허깅페이스 허브처럼 플랫폼처럼 느껴지게 합니다.

@HuggingFaceDocBuilderDev

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint.

Copy link
Member

@howsmyanimeprofilepicture howsmyanimeprofilepicture left a comment

Choose a reason for hiding this comment

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

Approve합니다. 😄

@tjdtnsu tjdtnsu merged commit 2d8f274 into Pseudo-Lab:main May 19, 2023
@tjdtnsu tjdtnsu deleted the opt branch May 19, 2023 10:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants