Unity-Technologies / ml-agents

The Unity Machine Learning Agents Toolkit (ML-Agents) is an open-source project that enables games and simulations to serve as environments for training intelligent agents using deep reinforcement learning and imitation learning.
https://unity.com/products/machine-learning-agents
Other
16.93k stars 4.13k forks source link

Building and Training on COLAB #2684

Closed taesiri closed 4 years ago

taesiri commented 4 years ago

Hi Everyone,

I'd like to share my own setup for training ml-agents on COLAB. It is a fairly simple setup but it helped me save some time. I make changes to the environment I want locally and push the changes to Github. After that, I build the environment in the COLAB and train the model I want. I should mention that installing Unity on COLAB and building a project taking 5 up to 15 minutes.

Here is the link to my COLAB notebook

Screen Shot 2019-10-07 at 12 31 42 AM

I used some scripts from unity3d-gitlab-ci-example for building the Unity project. For example, I copied and modified BuildCommand.cs into my project. The modification is in the GetEnabledScenes method and it's only 1 line. I only return the name of the scene I want to get build.

The whole setup is very simple at the moment. If anyone from ml-agent team is interested, I can make a PR with an appropriate BuildCommand file and a sample notebook.

ervteng commented 4 years ago

Hi @taesiri, thank you for sharing! This will be useful for others for sure. @unityjeffrey perhaps we can look into linking the tutorial in some way?

xiaomaogy commented 4 years ago

Hi @taesiri, this looks really nice! I've tried to walk through your notebook, but on the step of "Activate Unity" I got a few error messages saying "invalid option -- o" etc, so I wasn't able to proceed.

image

taesiri commented 4 years ago

@xiaomaogy, I think you haven't installed Unity yet. Either $UNITY_EXEC is pointing to the wrong path or you've forgotten to accept the License Agreement.

Screen Shot 2019-10-15 at 1 52 15 AM

After executing the above cell, you have to accept the License Agreement by pressing y in the textbox which appeared bellow the cell.

That being said, It is better to activate Unity using the second method. For some reason passing the password in the command line is problematic.

taesiri commented 4 years ago

Here is a video demo of the notebook

xiaomaogy commented 4 years ago

@taesiri Thanks for the video, I will try again. I was really confused by "Upload ulf file in colab using the left side-bar.", because I wan't able to see the Files tab and switch to it, and the video helped me find it.

xiaomaogy commented 4 years ago

@taesiri I was able to go through the whole process and I really like it. I was especially impressed by the convenience of this solution, everything is laid out nicely in just one place. The tensorboard, training console and the files can all be managed in one place (if we can somehow visualize the unity, that would be even better).

Regarding the setup part, aside from a little bit confusion in the license activation part(and the video helped a lot), all of the other steps are really smooth. Nice job!

One thing I'm curious about is you mentioned that this setup helps you save time. Could you please elaborate more on this if you don't mind?

taesiri commented 4 years ago

@xiaomaogy I am glad you liked it. I prepared this notebook very quickly, and surely, we can add a better explanation for each cell to reduce confusion.

I also had some thoughts about visualizing Unity's output. I am pretty sure we can add it either through some sort of xvbf hack or a minor modification in the ml-agents.

About the time-saving part, I like to modify/create different environments, and training agents on them can be time-consuming (I only have two computers). With this setup, I can use COLAB to train more agents simultaneously. The training power part aside, I think it is really convenient to push your C# code changes to the GitHub and let the scripts do the compiling job for you. (After installing Unity in one COLAB session, you can reuse it until the session expires.) Surely one can make a Linux build locally and upload the binaries in COLAB (or in any other Linux servers), but it's time consuming compared to automatic builds. (I also have bad internet connection which makes upload process painful)

xunyiljg commented 4 years ago

Thank you for sharing. I have also successfully used colab.

taesiri commented 4 years ago

@xunyiljg I'm glad you liked it 😊.

Just a quick update:

Screen Shot 2019-10-24 at 10 41 30 PM

taesiri commented 4 years ago

Here is the Link to my updated notebook. It works with the latest beta version of ml-agents 0.11. I should mention that I am really happy with the changes made in this version.

Screen Shot 2019-11-05 at 8 54 30 AM

training

Happy Coding!

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had activity in the last 14 days. It will be closed in the next 14 days if no further activity occurs. Thank you for your contributions.

stale[bot] commented 4 years ago

This issue has been automatically closed because it has not had activity in the last 28 days. If this issue is still valid, please ping a maintainer. Thank you for your contributions.

vwxyzjn commented 4 years ago

@taesiri It doesn't work anymore. See

image

I think list_of_scenes needs to be adjusted

# list_of_scenes = list(Path('/content/my-agents/UnitySDK/Assets/ML-Agents/Examples/').rglob('*.unity'))
list_of_scenes = list(Path('/content/my-agents/Project/Assets/ML-Agents/Examples/').rglob('*.unity'))

Then I can choose a scene, but then when I try to build it, I have another error

image

I feel like there should be a guide on how to build all example envs headlessly... What if I want to train everything in the server where no GUI is available? The current guides do not seem to cover these instructions.

taesiri commented 4 years ago

Hi @vwxyzjn.

I do not maintain that notebook anymore as there was little to no feedback from the community. I have a version of this notebook that works with my own fork of mlagents. You are more than welcome to copy my notebook and fix the issue you mentioned. The master branch is changing rapidly; I strongly suggest to switch to one of the stable release branches.

Some notes for you:

Cheers, M

github-actions[bot] commented 3 years ago

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.