def test_hf_storage():

    key = "dummy"

    storage = HuggingFaceStorage()

    has_token = HfFolder().get_token()
    if not has_token:
        token = os.environ["HUGGING_FACE_TOKEN"]
        HfFolder().save_token(token)

    state_dict = storage.get(key)
    model.load_state_dict(state_dict)

    assert key in storage
    assert key in storage.models
예제 #2
0
def login_to_hub() -> None:
    """Login to huggingface hub"""
    access_token = HfFolder.get_token()
    if access_token is not None and HfApi()._is_valid_token(access_token):
        logging.info("Huggingface Hub token found and valid")
        HfApi().set_access_token(access_token)
    else:
        subprocess.call(["huggingface-cli", "login"])
        HfApi().set_access_token(HfFolder().get_token())
    # check if git lfs is installed
    try:
        subprocess.call(["git", "lfs", "version"])
    except FileNotFoundError:
        raise OSError(
            "Looks like you do not have git-lfs installed, please install. \
                      You can install from https://git-lfs.github.com/. \
                      Then run `git lfs install` (you only have to do this once)."
        )