DATA, AI

huggingface로 협업하기

def__init__ 2024. 10. 29. 15:58

팀 기능과 함께 모델 버전 관리, 협업 및 배포 지원을 제공해 팀 단위로 머신러닝 모델을 관리하는 데 유용한 Hugging Face 사용법을 정리한다.

Organization 생성

Organization을 만들면, 여러 팀원이 하나의 허깅페이스 계정에서 협업할 수 있게 된다. 팀 단위로 모델과 데이터셋을 관리하여, 모든 멤버가 동일한 리소스에 접근하고 업데이트할 수 있고, 각 멤버에게 관리자, 편집자, 읽기 전용 등의 권한을 부여할 수 있어, 팀 내에서 역할에 맞게 접근 권한을 설정할 수 있다. 그러기 위해서

1. 허깅페이스에 로그인한 후, 프로필 메뉴에서 "Create an Organization"을 선택

2. Organization 이름과 설명을 입력하고 생성

- 이때 Organization Username : 간단하게 사용할 팀명, Organization Full name : 팀명 풀네임

3. 생성된 Organization에 팀원을 초대하고 권한을 설정

이러한 형태로 만든 후 아래의 형태로 허깅페이스 업로드 가능하다.

def upload_to_huggingface(model, tokenizer, hf_token, hf_organization, hf_repo_id):
    try:
        model.push_to_hub(
            repo_id=hf_repo_id, organization=hf_organization, use_auth_token=hf_token
        )
        tokenizer.push_to_hub(
            repo_id=hf_repo_id, organization=hf_organization, use_auth_token=hf_token
        )
    except Exception as e:
        print(f"An error occurred while uploading to Hugging Face: {e}")