Skip to content

Commit

Permalink
Make registry.resolve return resolve config only
Browse files Browse the repository at this point in the history
  • Loading branch information
ines committed Sep 27, 2020
1 parent 873f2ec commit 88f0bd8
Show file tree
Hide file tree
Showing 19 changed files with 68 additions and 76 deletions.
10 changes: 5 additions & 5 deletions examples/00_intro_to_thinc.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@
"metadata": {},
"outputs": [],
"source": [
"loaded_config1, _ = registry.resolve(config1)\n",
"loaded_config1 = registry.resolve(config1)\n",
"loaded_config1"
]
},
Expand Down Expand Up @@ -301,7 +301,7 @@
"metadata": {},
"outputs": [],
"source": [
"loaded_config2, _ = registry.resolve(config2)\n",
"loaded_config2 = registry.resolve(config2)\n",
"loaded_config2"
]
},
Expand Down Expand Up @@ -368,7 +368,7 @@
"metadata": {},
"outputs": [],
"source": [
"loaded_config, filled_config = registry.resolve(config)\n",
"loaded_config = registry.resolve(config)\n",
"loaded_config"
]
},
Expand Down Expand Up @@ -469,7 +469,7 @@
"metadata": {},
"outputs": [],
"source": [
"loaded_config, _ = registry.resolve(config)\n",
"loaded_config = registry.resolve(config)\n",
"loaded_config"
]
},
Expand Down Expand Up @@ -516,7 +516,7 @@
"\"\"\"\n",
"\n",
"config = Config().from_str(CONFIG3)\n",
"loaded_config, _ = registry.resolve(config)\n",
"loaded_config = registry.resolve(config)\n",
"loaded_config"
]
},
Expand Down
2 changes: 1 addition & 1 deletion examples/02_transformers_tagger_bert.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@
"source": [
"from thinc.api import Config, registry\n",
"\n",
"C, _ = registry.resolve(Config().from_str(CONFIG))\n",
"C = registry.resolve(Config().from_str(CONFIG))\n",
"C"
]
},
Expand Down
4 changes: 2 additions & 2 deletions examples/03_pos_tagger_basic_cnn.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@
"metadata": {},
"outputs": [],
"source": [
"C, _ = registry.resolve(config)\n",
"C = registry.resolve(config)\n",
"C"
]
},
Expand Down Expand Up @@ -351,7 +351,7 @@
"metadata": {},
"outputs": [],
"source": [
"C, _ = registry.resolve(Config().from_str(CONFIG))\n",
"C = registry.resolve(Config().from_str(CONFIG))\n",
"C"
]
},
Expand Down
2 changes: 1 addition & 1 deletion examples/03_textcat_basic_neural_bow.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@
"source": [
"from thinc.api import registry, Config\n",
"\n",
"C, _ = registry.resolve(Config().from_str(CONFIG))\n",
"C = registry.resolve(Config().from_str(CONFIG))\n",
"C"
]
},
Expand Down
4 changes: 2 additions & 2 deletions examples/04_parallel_training_ray.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@
"source": [
"### Setting up the model\n",
"\n",
"Using the `CONFIG` defined above, we can load the settings and set up the model and optimizer. Thinc's `registry.resolve` will parse the config, resolve all references to registered functions and return a dict of the resolved objects and a filled config with all defaults."
"Using the `CONFIG` defined above, we can load the settings and set up the model and optimizer. Thinc's `registry.resolve` will parse the config, resolve all references to registered functions and return a dict of the resolved objects."
]
},
{
Expand All @@ -263,7 +263,7 @@
"outputs": [],
"source": [
"from thinc.api import registry, Config\n",
"C, _ = registry.resolve(Config().from_str(CONFIG))\n",
"C = registry.resolve(Config().from_str(CONFIG))\n",
"C"
]
},
Expand Down
2 changes: 1 addition & 1 deletion examples/benchmarks/lstm_tagger.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def main(pytorch: bool = False, gpu_id: int = -1):
print(f"Skipping {name}")
continue
set_backend(name, gpu_id)
C, _ = registry.resolve(Config().from_str(CONFIG))
C = registry.resolve(Config().from_str(CONFIG))
model = C["model"]
X, Y = get_dummy_data(**C["data"])
print("Copy to device")
Expand Down
2 changes: 1 addition & 1 deletion examples/transformers_tagger.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def main(path: Optional[Path] = None, out_dir: Optional[Path] = None):
# In the optimizer block we write @optimizers = "Adam.v1". This tells Thinc
# to use registry.optimizers to fetch the "Adam.v1" function. You can
# register your own functions as well and build up trees of objects.
C, _ = thinc.registry.resolve(config)
C = thinc.registry.resolve(config)
words_per_subbatch = C["training"]["words_per_subbatch"]
n_epoch = C["training"]["n_epoch"]
batch_size = C["training"]["batch_size"]
Expand Down
5 changes: 3 additions & 2 deletions thinc/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -704,10 +704,11 @@ def resolve(
schema: Type[BaseModel] = EmptySchema,
overrides: Dict[str, Any] = {},
validate: bool = True,
) -> Tuple[Dict[str, Any], Config]:
return cls._make(
) -> Dict[str, Any]:
resolved, _ = cls._make(
config, schema=schema, overrides=overrides, validate=validate, resolve=True
)
return resolved

@classmethod
def fill(
Expand Down
6 changes: 2 additions & 4 deletions thinc/tests/layers/test_layers_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,7 @@ def assert_data_match(Y, out_data):
@pytest.mark.parametrize("name,kwargs,in_data,out_data", TEST_CASES)
def test_layers_from_config(name, kwargs, in_data, out_data):
cfg = {"@layers": name, **kwargs}
resolved, _ = registry.resolve({"config": cfg})
model = resolved["config"]
model = registry.resolve({"config": cfg})["config"]
if "LSTM" in name:
model = with_padded(model)
valid = True
Expand All @@ -139,8 +138,7 @@ def test_layers_from_config(name, kwargs, in_data, out_data):
@pytest.mark.parametrize("name,kwargs,in_data,out_data", TEST_CASES_SUMMABLE)
def test_layers_with_residual(name, kwargs, in_data, out_data):
cfg = {"@layers": "residual.v1", "layer": {"@layers": name, **kwargs}}
resolved, _ = registry.resolve({"config": cfg})
model = resolved["config"]
model = registry.resolve({"config": cfg})["config"]
if "LSTM" in name:
model = with_padded(model)
model.initialize(in_data, out_data)
Expand Down
3 changes: 1 addition & 2 deletions thinc/tests/layers/test_transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ def array_data(ragged_data):


def check_transform(transform, in_data, out_data):
resolved, _ = registry.resolve({"config": {"@layers": transform}})
model = resolved["config"]
model = registry.resolve({"config": {"@layers": transform}})["config"]
input_checker = get_data_checker(in_data)
output_checker = get_data_checker(out_data)
model.initialize(in_data, out_data)
Expand Down
Loading

0 comments on commit 88f0bd8

Please sign in to comment.