Commit 367cf380 authored by jameskrw's avatar jameskrw
Browse files

sokoban grpo text debug finished

parent 54a0b22a
Loading
Loading
Loading
Loading
+0 −11
Original line number Diff line number Diff line
seed: 42
train_path: "./data/sokoban-text-1-step/train.parquet"
test_path: "./data/sokoban-text-1-step/test.parquet"
"env1": {
  "env_name": "sokoban",
  'env_config': {
      'num_boxes': 1
  },
  "train_size": 1000,
  "test_size": 100,
}
 No newline at end of file
+2 −2
Original line number Diff line number Diff line
@@ -14,11 +14,11 @@ class BaseEnv(ABC):
        
        obs: {
            'obs_str': "This is the obs template, you see <image> and <image>, you heard <audio> and <audio>",
            'multi_modal_inputs':{
            'multi_modal_data':{
                '<image>':[list of images],
                '<audio>':[list of audios],
            }
            # num of <image> and <audio> in the obs_str should match len(multi_modal_inputs['<image>']) and len(multi_modal_inputs['<audio>'])
            # num of <image> and <audio> in the obs_str should match len(multi_modal_data['<image>']) and len(multi_modal_data['<audio>'])
        }
        info: {
            "metrics": {
+11 −14
Original line number Diff line number Diff line
@@ -5,19 +5,19 @@ import yaml
import argparse
from datasets import Dataset, load_dataset
from vagen.env.utils.env_utils import permanent_seed
def create_dataset_from_yaml(yaml_file_path: str, force_gen=False):
def create_dataset_from_yaml(yaml_file_path: str, force_gen=False,seed=42,train_path='./train.parquet',test_path='./test.parquet'):
    """
    Create dataset from a YAML configuration file.
    
    Args:
        yaml_file_path (str): Path to the YAML configuration file
        force_gen (bool): Whether to force regeneration of existing datasets
        seed (int): Seed for random number generation
        train_path (str): Path to save the training dataset
        test_path (str): Path to save the testing dataset
        
    The YAML file should have the following structure:
    ```
    seed: 42
    train_path: path/to/train.parquet
    test_path: path/to/test.parquet
    env1:
        env_name: sokoban  # or frozenlake
        env_config:
@@ -42,29 +42,23 @@ def create_dataset_from_yaml(yaml_file_path: str, force_gen=False):
    else:
        yaml_config = yaml_file_path
    
    train_path = yaml_config.get('train_path')
    test_path = yaml_config.get('test_path')
    
    os.makedirs(os.path.dirname(train_path), exist_ok=True)
    os.makedirs(os.path.dirname(test_path), exist_ok=True)
    
    if not force_gen and os.path.exists(train_path) and os.path.exists(test_path):
        print(f"Dataset files already exist at {train_path} and {test_path}. Skipping generation.")
        print(f"Use --force-gen to override and regenerate the dataset.")
        return
        return train_path, test_path
    
    
    train_instances = []
    test_instances = []
    
    global_seed = yaml_config.get('seed', 42)
    global_seed = seed
    permanent_seed(global_seed)
    
    
    for key, value in yaml_config.items():
        if key in ['train_path', 'test_path','seed']:
            continue
        
        env_name = value.get('env_name')
        custom_env_config = value.get('env_config', {})
        train_size,test_size = (value.get('train_size', 100), value.get('test_size', 100))
@@ -132,9 +126,12 @@ if __name__ == "__main__":
    parser = argparse.ArgumentParser()
    parser.add_argument("--yaml_path", type=str, required=True, help="Path to YAML configuration file")
    parser.add_argument("--force_gen", action="store_true", help="Force regenerate dataset even if exists")
    parser.add_argument("--train_path", type=str, default="./train.parquet", help="Path to save the training dataset")
    parser.add_argument("--test_path", type=str, default="./test.parquet", help="Path to save the testing dataset")
    parser.add_argument("--seed", type=int, default=42, help="Seed for random number generation")
    args = parser.parse_args()

    train_path, test_path = create_dataset_from_yaml(args.yaml_path, args.force_gen)
    print(args)
    train_path, test_path = create_dataset_from_yaml(args.yaml_path, args.force_gen, args.seed, args.train_path, args.test_path)
    
    # Optionally load the dataset and print examples
    train_dataset = load_dataset('parquet', data_files={"train": train_path}, split="train")
+6 −6
Original line number Diff line number Diff line
@@ -137,11 +137,11 @@ class FrozenLakeEnv(BaseEnv):

    def _render(self, init_obs=False):
        """Render the environment"""
        multi_modal_inputs = None
        multi_modal_data = None
        
        if self.config.render_mode == 'vision':
            img_placeholder = self.config.image_placeholder
            multi_modal_inputs = {
            multi_modal_data = {
                img_placeholder: [convert_numpy_to_PIL(self.gym_env._render_gui(mode='rgb_array'))]
            }
            img_str = img_placeholder
@@ -160,10 +160,10 @@ class FrozenLakeEnv(BaseEnv):
                done=self._finished(),
            )
        
        if multi_modal_inputs is not None:
        if multi_modal_data is not None:
            return {
                "obs_str": obs_str,
                "multi_modal_inputs": multi_modal_inputs,
                "multi_modal_data": multi_modal_data,
            }
        else:
            return {
@@ -216,7 +216,7 @@ if __name__ == "__main__":
    import os
    if config.render_mode == 'vision':
        os.makedirs("./test_frozenlake", exist_ok=True)
        img = obs["multi_modal_inputs"][config.image_placeholder][0]
        img = obs["multi_modal_data"][config.image_placeholder][0]
        img.save(f"./test_frozenlake/frozenlake_{i}.png")
    while True:
        i += 1
@@ -226,7 +226,7 @@ if __name__ == "__main__":
        print(obs["obs_str"])
        if config.render_mode == 'vision':
            # save the image
            img = obs["multi_modal_inputs"][config.image_placeholder][0]
            img = obs["multi_modal_data"][config.image_placeholder][0]
            img.save(f"./test_frozenlake/frozenlake_{i}.png")
        if done:
            break
+1 −1
Original line number Diff line number Diff line
@@ -6,7 +6,7 @@ class SokobanConfig(BaseConfig):
    dim_room: tuple = (6, 6)
    max_steps: int = 100
    num_boxes: int = 1
    render_mode: str = "vision"
    render_mode: str = "vision" # "vision" or "text"
    min_actions_to_succeed: int = 5
    max_actions_per_step: int = 3
    
Loading