Skip to content

Commit 38d88bd

Browse files
authored
Merge pull request #2 from burtenshaw/deploy-to-hf-spaces
Deploy to hf spaces
2 parents c25298c + 3cfe697 commit 38d88bd

27 files changed

+4445
-475
lines changed

.env.example

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Copy this file to .env and customize as needed
2+
3+
# Gitea Service Configuration
4+
GITEA_URL=http://host.docker.internal:3000
5+
GITEA_USERNAME=gitea
6+
GITEA_PASSWORD=gitea123

.github/workflows/deploy-hf-env.yml

Lines changed: 31 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,21 @@ on:
2020
required: false
2121
type: string
2222
default: ''
23+
hf_namespace:
24+
description: 'Hugging Face namespace to deploy to (leave empty for openenv)'
25+
required: false
26+
type: string
27+
default: 'openenv'
28+
private:
29+
description: 'Deploy the space as private (default: public)'
30+
required: false
31+
type: boolean
32+
default: false
33+
space_suffix:
34+
description: 'Suffix to add to space name (e.g., "-test" for test spaces)'
35+
required: false
36+
type: string
37+
default: ''
2338

2439
env:
2540
HF_USERNAME: openenv
@@ -101,73 +116,22 @@ jobs:
101116
- name: Checkout repository
102117
uses: actions/checkout@v4
103118

104-
- name: Set up Git
105-
run: |
106-
git config --global user.email "github-actions[bot]@users.noreply.github.com"
107-
git config --global user.name "github-actions[bot]"
108-
109-
- name: Prepare files for HF Space
119+
- name: Install Hugging Face CLI
110120
run: |
111-
chmod +x scripts/prepare_hf_deployment.sh
112-
./scripts/prepare_hf_deployment.sh "${{ matrix.environment }}" "${{ github.event.inputs.base_image_sha || '' }}"
121+
curl -LsSf https://hf.co/cli/install.sh | bash
122+
echo "$HOME/.local/bin" >> $GITHUB_PATH
113123
114124
- name: Deploy to Hugging Face Space
115125
env:
116126
HF_TOKEN: ${{ secrets.HF_TOKEN }}
117-
HF_USERNAME: openenv
127+
HF_NAMESPACE: ${{ env.HF_USERNAME }}
118128
run: |
119-
ENV_NAME="${{ matrix.environment }}"
120-
SPACE_NAME="$ENV_NAME"
121-
122-
echo "Deploying $ENV_NAME environment to HF Space: $SPACE_NAME"
123-
124-
# Clone the target space
125-
HF_SPACE_URL="https://$HF_USERNAME:[email protected]/spaces/$HF_USERNAME/$SPACE_NAME"
126-
echo "Cloning HF Space..."
127-
128-
if git clone $HF_SPACE_URL hf-space 2>/dev/null; then
129-
echo "Space exists, updating..."
130-
else
131-
echo "Space doesn't exist, will be created on first push"
132-
mkdir -p hf-space
133-
cd hf-space
134-
git init
135-
git remote add origin $HF_SPACE_URL
136-
cd ..
137-
fi
138-
139-
cd hf-space
140-
141-
# Clear existing files (except .git)
142-
find . -mindepth 1 -maxdepth 1 ! -name '.git' -exec rm -rf {} +
143-
144-
# Copy prepared files
145-
cp -r ../hf-staging_$ENV_NAME/* .
146-
147-
# Set the correct remote URL
148-
git remote set-url origin $HF_SPACE_URL
149-
150-
# Check if there are changes
151-
if [ -n "$(git status --porcelain)" ]; then
152-
echo "Committing changes..."
153-
git add .
154-
git commit -m "🤖 Deploy $ENV_NAME environment - $(date +'%Y-%m-%d %H:%M:%S')"
155-
156-
echo "Pushing to Hugging Face..."
157-
if git push origin main 2>/dev/null || git push origin master 2>/dev/null; then
158-
echo "✅ Successfully deployed to https://huggingface.co/spaces/$HF_USERNAME/$SPACE_NAME"
159-
else
160-
echo "❌ Failed to push to Hugging Face. Check your credentials and permissions."
161-
exit 1
162-
fi
129+
chmod +x scripts/deploy_to_hf.sh
130+
if [ -n "${{ github.event.inputs.base_image_sha }}" ]; then
131+
./scripts/deploy_to_hf.sh --env "${{ matrix.environment }}" --base-sha "${{ github.event.inputs.base_image_sha }}"
163132
else
164-
echo "ℹ️ No changes to deploy"
133+
./scripts/deploy_to_hf.sh --env "${{ matrix.environment }}"
165134
fi
166-
167-
# Cleanup
168-
cd ..
169-
rm -rf hf-space
170-
rm -rf hf-staging_$ENV_NAME
171135
172136
# Job to deploy single environment
173137
deploy-single:
@@ -184,70 +148,19 @@ jobs:
184148
- name: Checkout repository
185149
uses: actions/checkout@v4
186150

187-
- name: Set up Git
188-
run: |
189-
git config --global user.email "github-actions[bot]@users.noreply.github.com"
190-
git config --global user.name "github-actions[bot]"
191-
192-
- name: Prepare files for HF Space
151+
- name: Install Hugging Face CLI
193152
run: |
194-
chmod +x scripts/prepare_hf_deployment.sh
195-
./scripts/prepare_hf_deployment.sh "${{ matrix.environment }}" "${{ github.event.inputs.base_image_sha || '' }}"
153+
curl -LsSf https://hf.co/cli/install.sh | bash
154+
echo "$HOME/.local/bin" >> $GITHUB_PATH
196155
197156
- name: Deploy to Hugging Face Space
198157
env:
199158
HF_TOKEN: ${{ secrets.HF_TOKEN }}
200-
HF_USERNAME: openenv
159+
HF_NAMESPACE: ${{ env.HF_USERNAME }}
201160
run: |
202-
ENV_NAME="${{ matrix.environment }}"
203-
SPACE_NAME="$ENV_NAME"
204-
205-
echo "Deploying $ENV_NAME environment to HF Space: $SPACE_NAME"
206-
207-
# Clone the target space
208-
HF_SPACE_URL="https://$HF_USERNAME:[email protected]/spaces/$HF_USERNAME/$SPACE_NAME"
209-
echo "Cloning HF Space..."
210-
211-
if git clone $HF_SPACE_URL hf-space 2>/dev/null; then
212-
echo "Space exists, updating..."
213-
else
214-
echo "Space doesn't exist, will be created on first push"
215-
mkdir -p hf-space
216-
cd hf-space
217-
git init
218-
git remote add origin $HF_SPACE_URL
219-
cd ..
220-
fi
221-
222-
cd hf-space
223-
224-
# Clear existing files (except .git)
225-
find . -mindepth 1 -maxdepth 1 ! -name '.git' -exec rm -rf {} +
226-
227-
# Copy prepared files
228-
cp -r ../hf-staging_$ENV_NAME/* .
229-
230-
# Set the correct remote URL
231-
git remote set-url origin $HF_SPACE_URL
232-
233-
# Check if there are changes
234-
if [ -n "$(git status --porcelain)" ]; then
235-
echo "Committing changes..."
236-
git add .
237-
git commit -m "🤖 Deploy $ENV_NAME environment - $(date +'%Y-%m-%d %H:%M:%S')"
238-
239-
echo "Pushing to Hugging Face..."
240-
if git push origin main 2>/dev/null || git push origin master 2>/dev/null; then
241-
echo "✅ Successfully deployed to https://huggingface.co/spaces/$HF_USERNAME/$SPACE_NAME"
242-
else
243-
echo "❌ Failed to push to Hugging Face. Check your credentials and permissions."
244-
exit 1
245-
fi
161+
chmod +x scripts/deploy_to_hf.sh
162+
if [ -n "${{ github.event.inputs.base_image_sha }}" ]; then
163+
./scripts/deploy_to_hf.sh --env "${{ matrix.environment }}" --base-sha "${{ github.event.inputs.base_image_sha }}"
246164
else
247-
echo "ℹ️ No changes to deploy"
165+
./scripts/deploy_to_hf.sh --env "${{ matrix.environment }}"
248166
fi
249-
250-
# Cleanup
251-
cd ..
252-
rm -rf hf-space
253-
rm -rf hf-staging_$ENV_NAME

.github/workflows/docker-build.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ jobs:
7777
dockerfile: src/envs/sumo_rl_env/server/Dockerfile
7878
- name: atari-env
7979
dockerfile: src/envs/atari_env/server/Dockerfile
80+
- name: git-env
81+
dockerfile: src/envs/git_env/server/Dockerfile
8082

8183
steps:
8284
- name: Checkout code

README.md

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,20 @@
33
An e2e framework for creating, deploying and using isolated execution environments for agentic RL training, built using Gymnasium style simple APIs.
44

55
[![PyPI](https://img.shields.io/pypi/v/openenv-core?color=blue)](https://pypi.org/project/openenv-core/)
6+
[![Discord](https://img.shields.io/badge/Discord-OpenEnv-7289da?style=flat&logo=discord&logoColor=white)](https://discord.gg/YsTYBh6PD9)
67
[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/meta-pytorch/OpenEnv/blob/main/examples/OpenEnv_Tutorial.ipynb) **← Try the Interactive Tutorial!**
78

9+
---
10+
11+
**🚀 Featured Example:** Train LLMs to play BlackJack using [torchforge](https://github.com/meta-pytorch/torchforge) (PyTorch's agentic RL framework): [`examples/grpo_blackjack/`](examples/grpo_blackjack/)
12+
13+
## OpenEnv on partner platforms:
14+
15+
- [Lightning AI Studio](https://lightning.ai/environments?section=featured)
16+
- [TRL example](https://huggingface.co/docs/trl/main/en/openenv)
17+
- [Unsloth Google Colab](https://colab.research.google.com/github/unslothai/notebooks/blob/main/nb/OpenEnv_gpt_oss_(20B)_Reinforcement_Learning_2048_Game.ipynb)
18+
- [ART example](https://art.openpipe.ai/integrations/openenv-integration)
19+
820
## Overview
921

1022
OpenEnv provides a standard for interacting with agentic execution environments via simple Gymnasium style APIs - step(), reset(), state(). Users of agentic execution environments can interact with the environment during RL training loops using these simple APIs.
@@ -171,19 +183,22 @@ client.close() # Stops and removes container
171183
- smolagents (for coding environment)
172184

173185
## Supported RL Tools
174-
The goal of this project is to support a broad set of open and closed tools to help standardize the agentic RL community. If you have a project that supports OpenEnv environments, please put up a PR to add your tool name along with a link to your documentation.
186+
The goal of this project is to support a broad set of open and closed tools to help standardize the agentic RL community. If you have a project that supports OpenEnv environments, please put up a PR to add your tool name along with a link to your documentation.
175187

176188
### torchforge
177-
(coming soon)
189+
See GRPO BlackJack training example: [`examples/grpo_blackjack/`](examples/grpo_blackjack/)
178190

179191
### TRL
180-
(coming soon}
192+
See the [TRL example](https://huggingface.co/docs/trl/main/en/openenv) on how to integrate OpenEnv environments with GRPO training.
181193

182194
### Unsloth
183-
(coming soon)
195+
See the 2048 game example based on gpt-oss: [Colab notebook](https://colab.research.google.com/github/unslothai/notebooks/blob/main/nb/OpenEnv_gpt_oss_(20B)_Reinforcement_Learning_2048_Game.ipynb)
184196

185197
### SkyRL
186-
(coming soon)
198+
See the [SkyRL example](https://skyrl.readthedocs.io/en/latest/examples/openenv.html) on how to train on OpenEnv environments with SkyRL.
199+
200+
### ART
201+
See the [ART example](https://art.openpipe.ai/integrations/openenv-integration) on how OpenEnv environments can be used to train models with ART.
187202

188203
## Example Environments
189204

@@ -204,10 +219,10 @@ Executes arbitrary Python code in a sandboxed environment. Features:
204219

205220
See: [`src/envs/coding_env/README.md`](src/envs/coding_env/README.md)
206221

207-
## Community support & Acknowledgments
222+
## Community Support & Acknowledgments
208223
This is an open and community centric project. If you would like to add your name here, please put up a pull request and tag @jspisak for review. Ty!!
209224

210-
Supporters include: Meta-PyTorch, Hugging Face, [Surge AI](https://surgehq.ai), Unsloth AI, Reflection AI, vLLM, SkyRL (UC-Berkeley), LightningAI, Axolotl AI, ..
225+
Supporters include: Meta-PyTorch, Hugging Face, [Patronus AI](https://patronus.ai), [Surge AI](https://surgehq.ai), [LastMile AI](https://www.lastmileai.dev), Unsloth AI, Reflection AI, vLLM, SkyRL (UC-Berkeley), LightningAI, Axolotl AI, Stanford Scaling Intelligence Lab, Mithril, [OpenMined](https://openmined.org/) ..
211226

212227
And we'd also like to acknowledge the team at Farama Foundation as the OpenEnv API was heavily inspired by the work you all have done on Gymnasium. Cheers!
213228

0 commit comments

Comments
 (0)