Skip to content

Client library to download and publish environments, agents on the huggingbutt.com hub.

License

Notifications You must be signed in to change notification settings

3D-Wizard/huggingbutt

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

69 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

HuggingButt

Client library to download and publish reinforcement learning environments/agents on the huggingbutt.com hub. Join our Discord: https://discord.gg/fnrKcgPR9r

Installation

Removed dependency on ml-agents and added support for tiptoestep in the current version.

Create a new python environment using anaconda/miniconda.

conda create -n hb

activate the new python environment.

conda activate hb

install huggingbutt from pypi

pip install huggingbutt==0.0.5

or from source code

git clone -b v0.0.5 https://github.com/huggingbutt/huggingbutt.git
cd huggingbutt
python -m pip install .

If there is no error message printed during the installation, congratulations, you have successfully installed this package. Next, you need to apply an access token from the official website https://huggingbutt.com.

Register an account and login, just do as shown in the image below.

image

Click new token button generate a new token. This access token is mainly used to restrict the download times of each user, as the server cost is relatively high.

image

Congratulations, you now have an access token!

image

Just put the generated token in the task code and you're gooooood to go.

Here is a simple inference code:

import numpy as np
from huggingbutt import set_access_token, load_env, load_agent

HB_TOKEN = "YOUR_TOKEN"
set_access_token(HB_TOKEN)

if __name__ == '__main__':
    env = load_env("huggingbutt/roller_ball", "mac", silent=False, num=1, time_scale=20)
    agent = load_agent(4)
    obs, info = env.reset()
    steps = []
    rewards = []
    prev_i = 0
    epoch_reward = 0
    for i in range(1_000):
        act, _status_ = agent.predict(obs)
        obs, reward, terminated, truncated, info = env.step(act)
        epoch_reward += reward

        if terminated:
            obs, info = env.reset()
            # Statistics
            steps.append(i - prev_i)
            rewards.append(epoch_reward)
            prev_i = i
            epoch_reward = 0

    env.close()
    print(f"Played {len(steps)} times.")
    print("Mean steps:{}".format(np.mean(steps)))
    print("Mean reward:{}".format(np.mean(rewards)))

Training your agent for this environment.

import numpy as np
from huggingbutt import set_access_token, load_env, load_agent

HB_TOKEN = "YOUR_TOKEN"
set_access_token(HB_TOKEN)

if __name__ == '__main__':
    env = load_env("huggingbutt/roller_ball", "mac", silent=True, num=3, time_scale=20)
    model = PPO(
        "MlpPolicy",
        env,
        verbose=1,
        n_steps=512,
        tensorboard_log="./logs")
    
    model.learn(total_timesteps=1_000_000)
    model.save(f"roller_ball.zip")
    
    env.close()

I'm incredibly excited for you to upload the environment/agent you trained to huggingbutt.com. It would be amazing for everyone to study!

Upload your environment

1. Create a workspace directory.

Example: ~/huggingbutt/your_environment_name

2. Build your environment

Build your environment created based on Unity ML-Agents, save it to "your_environment_name/unity_package_name"

Filesystem structure:

Mac:

└── huggingbutt
    └── your_environment_name
        ├── your_environment_name.app
        └── your_environment_name_BurstDebugInformation_DoNotShip

Windows:

└── huggingbutt
    └── your_environment_name
        ├── your_environment_name.exe
        └── ...
        └── ...

3. Create config.toml file

Create a config.toml file in "your_environment_name" directory to specify where to load the executable from for the environment.

Filesystem structure:

└── huggingbutt
    ├── config.toml
    └── your_environment_name
        ├── your_environment_name.app
        └── your_environment_name_BurstDebugInformation_DoNotShip

Add the following content to config.toml

Mac:

[app]
  exe_file="unity_package_name/game.app"

Windows:

[app]
  exe_file="unity_package_name/game.exe"

Example:

image

4. Package and compress

You must ensure that after extracting the zip file, config.toml file is located in the root directory. image

5. Upload zip file

Click "Add Env"

image

Fill in basic information

image

We will redirect into add new version page after clicking "Save" button.

image

Click "My Envs" will list your environments.

image

image

Click the name of your environment will enter the detail page.

image

Click the blue badge named "* Versions" will list all versions of this environment.

image

Click "New Version" will enter add new version page.

todo

  1. Support more types learning environment, such as native game wrapped by python, pygame, class gym...

About

Client library to download and publish environments, agents on the huggingbutt.com hub.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%