Repository: ray-project/ray

Issue:
rllib rollout does not load the model automatically from params.json
<!--
General questions should be asked on the mailing list ray-dev@googlegroups.com.
Questions about how to use Ray should be asked on
[StackOverflow](https://stackoverflow.com/questions/tagged/ray).

Before submitting an issue, please fill out the following form.
-->

### System information
- **OS Platform and Distribution (e.g., Linux Ubuntu 16.04)**: Linux 4.4.0-135-generic x86_64 
- **Python version**: Python 3.6.5 

<!--
You can obtain the Ray version with

python -c "import ray; print(ray.__version__)"
-->

### Describe the problem
<!-- Describe the problem clearly here. -->

### Source code / logs
<!-- Include any logs or source code that would be helpful to diagnose the problem. If including tracebacks, please include the full traceback. Large logs and files should be attached. Try to provide a reproducible test case that is the bare minimum necessary to generate the problem. -->
rllib rollout does not load the model automatically from params.json for a simple 256x256x256x256 model. 
When I run rllib rollout without specifying --config with "model": {"fcnet_hiddens": [256, 256, 256, 256]} it fails with the following error:
```
    assert len(vector) == i, "Passed weight does not have the correct shape."
AssertionError: Passed weight does not have the correct shape.
```


Discussion:

Resolving patch:
diff --git a/python/ray/rllib/rollout.py b/python/ray/rllib/rollout.py
--- a/python/ray/rllib/rollout.py
+++ b/python/ray/rllib/rollout.py
@@ -12,6 +12,7 @@
 import gym
 import ray
 from ray.rllib.agents.registry import get_agent_class
+from ray.tune.util import merge_dicts
 
 EXAMPLE_USAGE = """
 Example Usage via RLlib CLI:
@@ -69,22 +70,23 @@ def create_parser(parser_creator=None):
 
 
 def run(args, parser):
-    config = args.config
-    if not config:
-        # Load configuration from file
-        config_dir = os.path.dirname(args.checkpoint)
-        config_path = os.path.join(config_dir, "params.pkl")
-        if not os.path.exists(config_path):
-            config_path = os.path.join(config_dir, "../params.pkl")
-        if not os.path.exists(config_path):
+    config = {}
+    # Load configuration from file
+    config_dir = os.path.dirname(args.checkpoint)
+    config_path = os.path.join(config_dir, "params.pkl")
+    if not os.path.exists(config_path):
+        config_path = os.path.join(config_dir, "../params.pkl")
+    if not os.path.exists(config_path):
+        if not args.config:
             raise ValueError(
                 "Could not find params.pkl in either the checkpoint dir or "
                 "its parent directory.")
+    else:
         with open(config_path, 'rb') as f:
             config = pickle.load(f)
-        if "num_workers" in config:
-            config["num_workers"] = min(2, config["num_workers"])
-
+    if "num_workers" in config:
+        config["num_workers"] = min(2, config["num_workers"])
+    config = merge_dicts(config, args.config)
     if not args.env:
         if not config.get("env"):
             parser.error("the following arguments are required: --env")


Test patch: