Commit fa1f4971 authored by root's avatar root Committed by YaningGao
Browse files

alfworld update

parent e99e1eba
Loading
Loading
Loading
Loading
+8 −4
Original line number Diff line number Diff line
## For Debugging
```
# Start a General Server in debug mode
python vagen/env/server.py --debug
python vagen/server/server.py --debug
```

## Environment Installation
@@ -54,15 +54,19 @@ pip install ai2thor==2.1.0
pip install alfworld==0.3.2
pip3 install numpy==1.23.5
pip3 install protobuf==3.20.3
pip3 install pydantic==1.10.14
pip3 install pydantic==2.10.6
pip3 install pydantic-core==2.16.3
pip3 uninstall frozenlist gradio murmurhash preshed spacy srsly thinc weasel aiosignal annotated-types blis catalogue cloudpathlib cymem

#skip this two install if you already installed in navigation
apt-get install -y pciutils
apt-get install -y xorg xserver-xorg-core xserver-xorg-video-dummy

# Set the data path and download before running the server
export ALFWORLD_DATA=<storage_path>
alfworld-download

# on a new window, start a startx port and then start server
python vagen/env/alfworld/startx.py
python vagen/env/server.py
python vagen/env/alfworld/startx.py 0
python vagen/server/server.py
```
+2 −2
Original line number Diff line number Diff line
@@ -2,8 +2,8 @@ dataset:
  data_path: '$ALFWORLD_DATA/json_2.1.1/train'
  eval_id_data_path: '$ALFWORLD_DATA/json_2.1.1/valid_seen'    # null/None to disable
  eval_ood_data_path: '$ALFWORLD_DATA/json_2.1.1/valid_unseen' # null/None to disable
  num_train_games: 10                                          # max training games (<=0 indicates full dataset)
  num_eval_games: 2                                           # max evaluation games (<=0 indicates full dataset)
  num_train_games: 1                                          # max training games (<=0 indicates full dataset)
  num_eval_games: 1                                           # max evaluation games (<=0 indicates full dataset)

logic:
  domain: '$ALFWORLD_DATA/logic/alfred.pddl'                   # PDDL domain file that defines the world dynamics
+6 −3
Original line number Diff line number Diff line
@@ -7,6 +7,7 @@ from .prompt import system_prompt_text, system_prompt_vision, init_observation_t
import alfworld.agents.environment
import numpy as np
import torch
import random

class ALFWorldEnv(BaseEnv):
    """ALFWorld environment adapter that maps the BaseEnv interface to ALFWorld interface"""
@@ -151,7 +152,6 @@ class ALFWorldEnv(BaseEnv):
        """
        # Handle seed manually if provided @TODO figure out better random way
        if seed is not None:
            import random
            random.seed(seed)
            
            np.random.seed(seed)
@@ -216,6 +216,11 @@ class ALFWorldEnv(BaseEnv):
        # Format the list of admissible commands
        commands_text = "\n".join([f"'{s}'" for s in self.prev_admissible_commands]) if self.prev_admissible_commands else ""
        
        if self.config.render_mode == "vision":
            img = self.env.get_frames()[0]
            img_placeholder = self.config.image_placeholder
            observation_text = f"{img_placeholder}\n{observation_text}"

        # Select appropriate template based on whether this is initial observation
        if init_obs:
            obs_str = init_observation_template.format(
@@ -233,8 +238,6 @@ class ALFWorldEnv(BaseEnv):
        
        # For text mode, just return the observation string
        if self.config.render_mode == "vision":
            img = self.env.get_frames()[0]
            img_placeholder = self.config.image_placeholder
            return {
                "obs_str": obs_str,
                "multi_modal_data": {img_placeholder: [convert_numpy_to_PIL(img)]}
+1 −3
Original line number Diff line number Diff line
# prompt.py

system_prompt_text = """You are an ALFRED household robot designed to perform household tasks in a text-based environment.

Task Guide:
@@ -26,7 +24,7 @@ system_prompt_vision = """You are an ALFRED household robot designed to perform
Task Guide:
You should follow the human instruction and complete tasks in a household environment.

You can take up to {max_actions_per_step} action(s) at a time, chosen from the available actions list.
You can take up to {max_actions_per_step} action(s) at a time, seperated by {action_sep}. Chosen from the available actions list.

Rewards:
- Correct format: +0.5
+14 −4
Original line number Diff line number Diff line
@@ -109,7 +109,10 @@ def start(display=0, width=1280, height=1024):
    # find NVIDIA GPUs
    buses = []
    for r in pci_records():
        if r.get('Vendor') == 'NVIDIA Corporation' and r.get('Class','').startswith('VGA'):
        if r.get('Vendor') == 'NVIDIA Corporation' and (
            r.get('Class','').startswith('VGA') or 
            r.get('Class','').startswith('3D')
        ):
            slot = r['Slot']  # e.g. '01:00.0'
            parts = re.split(r'[:\.]', slot)
            buses.append('PCI:' + ':'.join(str(int(x,16)) for x in parts))
@@ -123,17 +126,24 @@ def start(display=0, width=1280, height=1024):
    with os.fdopen(fd, 'w') as f:
        f.write(conf)

    # launch Xorg silently
    # launch Xorg in the foreground
    cmd = (
        f"Xorg -noreset +extension GLX +extension RANDR +extension RENDER "
        f"-config {path} :{display}"
    )
    subprocess.Popen(shlex.split(cmd), stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
    process = subprocess.Popen(shlex.split(cmd), stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    print(f"Started Xorg on DISPLAY=:{display}")
    
    # wait for Xorg process to complete (or manually stop it)
    out, err = process.communicate()
    
    if process.returncode != 0:
        print(f"Error starting Xorg: {err.decode()}")
        return
    
    # export DISPLAY for this process
    os.environ['DISPLAY'] = f":{display}"

    print(f"Xorg is running on DISPLAY=:{display}. You can stop it by killing the process.")

if __name__ == '__main__':
    import sys
Loading