Skip to content

Pin framework to tf in AIR rl offline trainer example - #33750

Merged
gjoliver merged 2 commits into
ray-project:masterfrom
avnishn:pin_offline_rl_example_to_use_tf
Mar 28, 2023
Merged

Pin framework to tf in AIR rl offline trainer example#33750
gjoliver merged 2 commits into
ray-project:masterfrom
avnishn:pin_offline_rl_example_to_use_tf

Conversation

@avnishn

@avnishn avnishn commented Mar 27, 2023

Copy link
Copy Markdown
Member

something broken about the way that torch ppo writes out to json

when using the output writer, torch ppo writes out sample batches in the incorrect format:

“value”: {”type”: “MultiAgentBatch”...

instead of just

{”type”: “MultiAgentBatch”...

Useful debug script:
https://gist.github.com/avnishn/c8599a9947edcd9934421713ed82f175

def generate_offline_data(path: str):
    print(f"Generating offline data for training at {path}")
    trainer = RLTrainer(
        algorithm="PPO",
        run_config=RunConfig(stop={"timesteps_total": 5000}),
        config={
            "env": "CartPole-v1",
            "output": "dataset",
            "output_config": {
                "format": "json",
                "path": path,
                "max_num_samples_per_file": 1,
            },
            "batch_mode": "complete_episodes",
            "framework": "tf"
        },
    )
    trainer.fit()
def train_rl_bc_offline(path: str, num_workers: int, use_gpu: bool = False) -> Result:
    print("Starting offline training")
    dataset = ray.data.read_json(
        path, parallelism=num_workers, ray_remote_args={"num_cpus": 1}
    )

    trainer = RLTrainer(
        run_config=RunConfig(stop={"training_iteration": 5}),
        scaling_config=ScalingConfig(num_workers=num_workers, use_gpu=use_gpu),
        datasets={"train": dataset},
        algorithm=BC,
        config={
            "env": "CartPole-v1",
            "framework": "tf",
            "evaluation_num_workers": 1,
            "evaluation_interval": 1,
            "evaluation_config": {"input": "sampler"},
            "framework": "tf"
        },
    )

    # Todo (krfricke/xwjiang): Enable checkpoint config in RunConfig
    # result = trainer.fit()
    tuner = Tuner(
        trainer,
        _tuner_kwargs={"checkpoint_at_end": True},
    )
    result = tuner.fit()[0]
    return result
ray.init(num_cpus=8)

path = "/tmp/out"
generate_offline_data(path)
result = train_rl_bc_offline(path=path, num_workers=2, use_gpu=False)

Should work with torch but doesn’t because of the way that sample batches are created.

Signed-off-by: Avnish avnishnarayan@gmail.com

Why are these changes needed?

Related issue number

Checks

  • I've signed off every commit(by using the -s flag, i.e., git commit -s) in this PR.
  • I've run scripts/format.sh to lint the changes in this PR.
  • I've included any doc changes needed for https://docs.ray.io/en/master/.
    • I've added any new APIs to the API Reference. For example, if I added a
      method in Tune, I've added it in doc/source/tune/api/ under the
      corresponding .rst file.
  • I've made sure the tests are passing. Note that there might be a few flaky tests, see the recent failures at https://flakey-tests.ray.io/
  • Testing Strategy
    • Unit tests
    • Release tests
    • This PR is not tested :(

Signed-off-by: Avnish <avnishnarayan@gmail.com>
@avnishn

avnishn commented Mar 27, 2023

Copy link
Copy Markdown
Member Author

corresponding issue:
#33751

@amogkam

amogkam commented Mar 27, 2023

Copy link
Copy Markdown
Contributor

can we fix the underlying issue instead?

@avnishn

avnishn commented Mar 27, 2023

Copy link
Copy Markdown
Member Author

coming in a separate pr @amogkam. I can't fix it before the release cut. This will unblock for now

@amogkam

amogkam commented Mar 27, 2023

Copy link
Copy Markdown
Contributor

@gjoliver @matthewdeng please review

"name": "stderr",
"output_type": "stream",
"text": [
"2022-09-26 18:22:15,032\tINFO worker.py:1509 -- Started a local Ray instance. View the dashboard at \u001b[1m\u001b[32m127.0.0.1:8265 \u001b[39m\u001b[22m\n"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should keep the output?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure thing

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok all done.

@gjoliver

Copy link
Copy Markdown
Member

wait the branch cut has already passed, do we still need this?

@avnishn

avnishn commented Mar 27, 2023

Copy link
Copy Markdown
Member Author

branch cut is tonight at midnight. I was asked to make this fix since this test was red on master but I'll defer to you guys instead to determine whether or not this needs to be merged.

Signed-off-by: Avnish <avnishnarayan@gmail.com>
@gjoliver
gjoliver merged commit d5b9727 into ray-project:master Mar 28, 2023
elliottower pushed a commit to elliottower/ray that referenced this pull request Apr 22, 2023
)

Signed-off-by: Avnish <avnishnarayan@gmail.com>
Signed-off-by: elliottower <elliot@elliottower.com>
ProjectsByJackHe pushed a commit to ProjectsByJackHe/ray that referenced this pull request May 4, 2023
)

Signed-off-by: Avnish <avnishnarayan@gmail.com>
Signed-off-by: Jack He <jackhe2345@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants