Buckets:

hf-doc-build/doc-dev / openenv /pr_749 /en /guides /rl-integration.md
HuggingFaceDocBuilder's picture
|
download
raw
1.68 kB

RL Framework Integration

This page is still being filled in. TRL integration is covered below; torchforge and SkyRL integrations are planned.

Use OpenEnv with popular RL frameworks like TRL, torchforge, and SkyRL.

Overview

OpenEnv environments are designed to integrate seamlessly with RL training frameworks. The standard step(), reset(), state() API makes it easy to use environments in training loops.

TRL Integration

TRL (Transformer Reinforcement Learning) is the recommended framework for training language models with RL.

from trl import GRPOTrainer
from openenv import AutoEnv, AutoAction

env = AutoEnv.from_env("textarena")
TextAction = AutoAction.from_env("textarena")

# Use with TRL's GRPO trainer
trainer = GRPOTrainer(
    model=model,
    reward_model=reward_model,
    # ... TRL config
)

See the Wordle with GRPO tutorial for a complete example.

Generic Training Loop

For custom training setups:

from openenv import AutoEnv, AutoAction

env = AutoEnv.from_env("my-env")
Action = AutoAction.from_env("my-env")

with env.sync() as client:
    for episode in range(num_episodes):
        result = client.reset()

        while not result.terminated:
            # Get action from your policy
            action = policy(result.observation)

            # Take step
            result = client.step(action)

            # Update policy with reward
            policy.update(result.reward)

Next Steps

Xet Storage Details

Size:
1.68 kB
·
Xet hash:
de0c726df74515d8f0b71b9b3df9c9b6cd38d6e76cd040f29fc60d66334edcd1

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.