{"id":19287333,"url":"https://github.com/opendilab/huggingface_ding","last_synced_at":"2025-11-06T23:04:00.256Z","repository":{"id":173882341,"uuid":"605898693","full_name":"opendilab/huggingface_ding","owner":"opendilab","description":"Auxiliary code for pulling, loading reinforcement learning models based on DI-engine from the Huggingface Hub, or pushing them onto Huggingface Hub with auto-created model card.","archived":false,"fork":false,"pushed_at":"2023-12-12T06:03:21.000Z","size":43,"stargazers_count":52,"open_issues_count":0,"forks_count":3,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-22T05:22:12.468Z","etag":null,"topics":["decision-making","huggingface","reinforcement-learning"],"latest_commit_sha":null,"homepage":"https://huggingface.co/OpenDILabCommunity","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/opendilab.png","metadata":{"files":{"readme":"README.cn.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2023-02-24T06:15:01.000Z","updated_at":"2025-01-08T07:59:17.000Z","dependencies_parsed_at":null,"dependency_job_id":"6be36598-7b8f-47ca-9804-428221cc385f","html_url":"https://github.com/opendilab/huggingface_ding","commit_stats":null,"previous_names":["opendilab/huggingface_ding"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/opendilab/huggingface_ding","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/opendilab%2Fhuggingface_ding","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/opendilab%2Fhuggingface_ding/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/opendilab%2Fhuggingface_ding/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/opendilab%2Fhuggingface_ding/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/opendilab","download_url":"https://codeload.github.com/opendilab/huggingface_ding/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/opendilab%2Fhuggingface_ding/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":283095890,"owners_count":26778518,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-11-06T02:00:06.180Z","response_time":55,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["decision-making","huggingface","reinforcement-learning"],"created_at":"2024-11-09T22:05:52.737Z","updated_at":"2025-11-06T23:04:00.236Z","avatar_url":"https://github.com/opendilab.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Hugging Face 🤗 x OpenDILab/DI-engine\n\n[English](./README.md) | 简体中文\n\n\u003e Huggingface_ding 代码库用于提供 Huggingface Hub 的 API 封装，可以用于快速拉取 OpenDILab/DI-engine 的公开模型，或是可以将使用 OpenDILab/DI-engine 训练的模型推送至 Huggingface Hub.\n\n\u003c!-- toc --\u003e\n\n- [安装方法](#安装方法)\n- [案例](#案例)\n  - [下载模型](#下载模型)\n  - [上传模型](#上传模型)\n- [API说明](#api说明)\n\n# 安装方法\n## 使用 pip 安装\n```\npip install -e .\n```\n\n# 案例\n## 下载模型\n\n从 Huggingface Hub 下载一个模型，部署评估，并渲染生成对应的视频回放：\n```python\nfrom ding.bonus import TD3Agent\nfrom huggingface_ding import pull_model_from_hub\n\n# Pull model from Hugggingface hub\npolicy_state_dict, cfg=pull_model_from_hub(repo_id=\"OpenDILabCommunity/LunarLander-v2-TD3\")\n# Instantiate the agent\nagent = TD3Agent(env=\"lunarlander_continuous\",exp_name=\"LunarLander-v2-TD3\", cfg=cfg.exp_config, policy_state_dict=policy_state_dict)\n# Continue training\nagent.train(step=5000)\n# Render the new agent performance\nagent.deploy(enable_save_replay=True)\n\n```\n\n## 上传模型\n\n使用 DI-engine 训练了一个模型，并将其推送至 Huggingface Hub，自动制作生成 Modelcard\n```python\nfrom ding.bonus import TD3Agent\nfrom huggingface_ding import push_model_to_hub\n\n# Instantiate the agent\nagent = TD3Agent(\"lunarlander_continuous\", exp_name=\"LunarLander-v2-TD3\")\n# Train the agent\nreturn_ = agent.train(step=int(4000000), collector_env_num=4, evaluator_env_num=4)\n# Push model to huggingface hub\npush_model_to_hub(\n    agent=agent.best,\n    env_name=\"OpenAI/Gym/Box2d\",\n    task_name=\"LunarLander-v2\",\n    algo_name=\"TD3\",\n    wandb_url=return_.wandb_url,\n    github_repo_url=\"https://github.com/opendilab/DI-engine\",\n    github_doc_model_url=\"https://di-engine-docs.readthedocs.io/en/latest/12_policies/td3.html\",\n    github_doc_env_url=\"https://di-engine-docs.readthedocs.io/en/latest/13_envs/lunarlander.html\",\n    installation_guide=\"pip3 install DI-engine[common_env,fast]\",\n    usage_file_by_git_clone=\"./td3/lunarlander_td3_deploy.py\",\n    usage_file_by_huggingface_ding=\"./td3/lunarlander_td3_download.py\",\n    train_file=\"./td3/lunarlander_td3.py\",\n    repo_id=\"OpenDILabCommunity/LunarLander-v2-TD3\"\n)\n```\n\n# API说明\n\n**pull_model_from_hub**\n\n参数列表:\n\n- agent (:obj:`object`): 需要上传的智能体\n- env_name (:obj:`str`): 任务所属的环境名\n- task_name (:obj:`str`): 智能体决策的任务名\n- algo_name (:obj:`str`): 算法名\n- wandb_url (:obj:`str`): wandb 网页地址，用于记录训练过程\n- repo_id (:obj:`str`): Huggingface Hub 仓库 ID\n- usage_file_by_git_clone (:obj:`str`): 描述从 Huggingface Hub 使用 git clone 方法下载至本地的模型应该如何使用的文件的路径\n- usage_file_by_huggingface_ding (:obj:`str`): 描述使用 huggingface ding 下载的模型应该如何使用的文件的路径\n- train_file (:obj:`str`): 描述该模型是如何被训练的文件的路径\n- github_repo_url (:obj:`str`): github 网页地址，用于指示该模型所依赖的 DI-engine 仓库\n- github_doc_model_url (:obj:`str`): github 或相关文档的网页地址，用于描述模型\n- github_doc_env_url (:obj:`str`): github 或相关文档的网页地址，用于描述任务环境\n- model_description (:obj:`str`): 一段描述该模型的简单介绍\n- installation_guide (:obj:`str`): 描述任务环境的安装方法\n- create_repo (:obj:`bool`): 是否需要创建 Huggingface Hub 仓库\n\n**push_model_to_hub**\n\n参数列表:\n\n- repo_id (:obj:`str`): Huggingface Hub 仓库 ID","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopendilab%2Fhuggingface_ding","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fopendilab%2Fhuggingface_ding","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopendilab%2Fhuggingface_ding/lists"}