Airgapped AI Center에 custom ML 패키지 업로드하기

인터넷 연결이 불가능한 airgapped AI Center에 custom ML 패키지를 업로드할 때에는 python package dependency를 로컬에서 해결해주어야 합니다. 인터넷 연결이 없어서 업로드한 ML 패키지가 요구하는(참조하는) python 패키지들을 다운로드하지 못하기 때문입니다.

AI Center에 업로드하려고 하는 ML 패키지가 afinn이라는 패키지를 참조한다면, ML 패키지 작성 가이드에 따라 requirements.txt 파일에 아래와 같이 명시하게 됩니다.

afinn==0.1

인터넷 연결이 없는 AI Center에 이 패키지를 그대로 업로드하면 이것을 ML skill로 deploy 할 때 아래와 같은 에러를 만나게 됩니다.

Error while creating docker image for image 10.96.0.246/host/0099f677_2552_4971_9d02_92d132d6bb57/fe677eca_9b16_4f06_891b_d52e6652868d/test_afinn_online:1 with details ERROR: Could not find a version that satisfies the requirement afinn==0.1 (from -r requirements.txt (line 1)) (from versions: none)ERROR: No matching distribution found for afinn==0.1 (from -r requirements.txt (line 1))ERROR: An error occurred: non-zero (13) exit code from 10.96.0.246/ai-fabric/UiPath-UiPath-core-s2i-python36:0.4-AIF

이 에러를 피하려면 afinn 패키지를 custom 패키지 안에 포함시켜 주어야 합니다. 인터넷에 연결된 환경에서 아래와 같이 해주면 됩니다.

  1. 아래의 명령어를 사용하여 afinn 패키지를 설치(다운로드)합니다.
    $ pip install afinn

  2. 아래의 명령어를 사용하여 afinn 패키지가 설치된 경로를 확인합니다.
    $ pip show afinn

    $ pip show afinn
    Name: afinn
    Version: 0.1
    Summary: AFINN sentiment analysis
    Location: /home/aiadmin/.local/lib/python3.6/site-packages

  3. afinn 폴더를 custom 패키지의 루트 폴더 아래로 복사해옵니다. 복사 후 폴더 구조는 아래와 같습니다.

    custom_package_root/
        afinn/
            data/
               ...
            __pycache__/
               ...
            afinn.py
            __init__.py
        main.py
        requirements.txt
        ...
    
  4. requirements.txt 파일은 내용을 모두 지워서 비워둡니다.

  5. 가져온 패키지의 dependency들도 모두 동일한 방법으로 가져와야 합니다. 패키지의 dependency 정보는 pip show 커맨드 출력의 Requires: 섹션에서 확인할 수 있지만, 하위 dependency까지 정리하여 보여주는 pipdeptree를 사용하면 보다 손쉽게 파악할 수 있습니다. 아래의 커맨드로 설치할 수 있습니다.

    $ pip install pipdeptree