Google Tensor SDK를 사용하면 Google Tensor의 전용 TPU에서 머신러닝 (ML) 모델을 직접 최적화하고 실행할 수 있습니다. 표준 ML 모델 외에도 LiteRT 워크플로 내에서 언어 모델을 컴파일하고 가속화할 수 있습니다.
특정 사전 최적화 모델의 경우 워크플로에 포함할 수 있는 추가 컴파일러 옵션 바이너리 파일도 제공됩니다. Google Tensor에서 최적의 성능을 달성하려면 컴파일 중에 다음 최적화 플래그를 사용하는 것이 좋습니다.
Google Tensor 컴파일 플래그
특정 구성 플래그를 적용하여 성능과 리소스 사용량을 맞춤설정하여 모델 컴파일 프로세스를 최적화합니다. LiteRT Python 워크플로 내에서 이러한 매개변수를 사용하여 PyTorch 및 TFLite 모델의 컴파일 동작을 조정할 수 있습니다.
| 플래그 | 요구사항 | 설명 | 기본값 |
|---|---|---|---|
google_tensor_truncation_type |
선택사항 | 부동 소수점 연산의 대상 데이터 유형을 설정합니다. 지원되는 값: auto (기본값), bfloat16, half, no_truncation |
자동 |
google_tensor_sharding_intensity |
선택사항 | 병렬 처리를 위해 모델이 분할되는 정도를 제어합니다. 옵션: minimal, moderate, extensive, maximum |
미니멀 |
google_tensor_int64_to_int32 |
선택사항 | 컴파일러가 64비트 정수를 32비트 정수로 변환하도록 허용하려면 true로 설정합니다. 이는 일부 모델에 필요할 수 있습니다. | 거짓 |
google_tensor_enable_large_model_support |
선택사항 | 모델이 2GB보다 큰 경우 true로 설정합니다. | 거짓 |
google_tensor_enable_4bit_compilation |
선택사항 | 4비트 매개변수가 포함된 컨볼루션 연산으로 모델을 컴파일할 수 있습니다. | 거짓 |
google_tensor_extra_options_path |
선택사항 | 추가 컴파일러 옵션을 바이너리 파일로 전달합니다. | '' (비어 있음) |
다음 코드 스니펫에 표시된 대로 LiteRT Python 흐름과 함께 이러한 플래그를 사용할 수 있습니다.
ai_edge_torch를 사용하여 PyTorch 모델을 컴파일하는 경우compiled_models = ( ai_edge_torch.experimental_add_compilation_backend(tensor_g5_target, flag_name1=value1, flag_name2=value2, ...).convert( channel_last_selfie_segmentation, sample_input))tflite 모델을 컴파일할 때
compiled_models = aot_lib.aot_compile( tflite_model_path, target=[tensor_g5_target], flag_name1=value1, flag_name2=value2, ...)
사용 예
다음 예에서는 google_tensor_truncation_type="half" 플래그가 사용됩니다.
compiled_models = aot_lib.aot_compile(
tflite_model_path,
target=[tensor_g5_target],
keep_going=False,
google_tensor_truncation_type="half"
)
자세한 내용은 LiteRT AOT Colab을 참고하세요.
Google Tensor용 언어 모델 컴파일
Google Tensor용 언어 모델을 컴파일하려면 NPU AOT 컴파일의 안내를 따르세요.
Google Tensor TPU용 LLM을 내보내려면 NPU 컴파일에 필요한 추가 플래그의 예를 따르세요.
예:
litert-torch export-hf \
--model=google/gemma-3-270m-it \
--output_dir=/tmp/gemma3-270m-google-tensor-g5 \
--split_cache \
--externalize_embedder \
--prefill_lengths=128, \
--cache_length=1280 \
--quantization_recipe="weight_only_wi8_afp32" \
--aot_backend=GOOGLE \
--aot_soc_model=Tensor_G5 \
--aot_compilation_config_dict='{"google_tensor_enable_large_model_support": True}'