2024년 3월 4일 월요일

intel imac에서 tensorflow gpu 사용하기

 우선 python3.8버전을 설치하여야합니다.

$ brew list 하여 python@3.8 버전이 설치되어 있는지 확인합니다.

설치는 $brew install phthon@3.8

링크는 $brew link python@3.8

확인은 $python3.8 --version

만약 필요가 없어지면 uninstall, unlink를 사용하면 됩니다.

가상환경을 만듭니다.

$python3.8 -m venv venv #2번째 venv는 폴더명

가상환경들어가기

$source ~/venv/bin/source

(venv) $ 로 프롬프트가 바뀜니다

(venv) $ python --version 하여 가상환경에 설치된 파이썬 버전을 확인합니다.

(venv) $ pip list 확인후 pip 버전을 업그레이드 합니다.

(venv) $ python -m pip install -U pip

(venv) $ pip install tensorflow-macos

(venv) $ pip install tensorflow-metal

(venv) $ code 하여 vscode를 실행합니다

import tensorflow as tf
devices = tf.config.list_physical_devices()
print("\nDevices: ", devices)

gpus = tf.config.list_physical_devices('GPU')
if gpus:
details = tf.config.experimental.get_device_details(gpus[0])
print("GPU details: ", details)

을 실행하여 확인합니다.

처음실행하면 vscode에서 ikernel을 자동으로 설치합니다.

결과는

Devices:  

[PhysicalDevice(name='/physical_device:CPU:0', device_type='CPU'), 

PhysicalDevice(name='/physical_device:GPU:0', device_type='GPU')] GPU details: {'device_name': 'METAL'}

하여 확인할 수 있습니다.



조금 빨라지려나....

GPU를 사용하면 처리속도가 더 늦어지는 것 같음....

댓글 없음:

tensorflow gpu 사용하기에서

 tensorflow 설치시 주의해야 한다. # Anything above 2.10 is not supported on the GPU on Windows Native python - m pip install "tensorflow<2.11...