Join GitHub today
GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
NetSpec: don't require lists to specify single-element repeated fields #2959
Conversation
jeffdonahue
added ready for review JL
labels
Aug 22, 2015
|
I did consider this interface, but decided against it. Happy to hear what others think, though.
On the other hand, this behavior mirrors the protobuf behavior (as text, but not the API), and is similar to the way |
|
Yeah, I understand the concerns; I think the best argument is that this mirrors the prototxt behavior and gives the |
|
I'd side with @jeffdonahue here. It would be a lot more convenient to be able to specify repeated fields with a scalar. If that's not possible, it would be nice to at least make the error handling a bit better. For example throw an exception the moment someone tries to assign a single value to a repeated field and not once to_proto is called. |
|
@philkr as I'd expect :) To be clear, what we're discussing here is type coercion. For shapes, this form of weak typing is accepted in the Net spec, in my view, need not merely wrap protobuf; it's an opportunity to write the language we most want (within the constraints of being a Python EDSL, which has its own set of issues, which are different from those of protobuf). So the argument of mirroring protobuf behavior doesn't resonate very loudly with me; if we forget protobuf entirely, what should the language of nets look like? Now I totally agree that exception handling needs dramatic improvements (PRs welcome!); that is one area that I just didn't get to on the first pass. At the very least, common errors ought to produce sensible messages. I also agree that it would be better to fail earlier, although that is a bit tricky in the current implementation, because protobuf generation is delayed as long as possible. (This is intentional, so that there is a complete non-protobuf representation of the net (suitable, the intention is, for easy processing and transformation), which means the specification doesn't meet the protobuf types until generation time.) Perhaps the types should be parsed and drawn into the Python graph IR to meet the specification, or perhaps we should just accept the protobuf IR from the beginning and generate it at once. For my own workflow, this hasn't been a huge deal, since I am never specifying a net without immediately calling |
This was referenced Aug 24, 2015
shelhamer
added the
focus
label
Aug 31, 2015
longjon
commented on an outdated diff
Sep 3, 2015
| @@ -58,6 +58,9 @@ def assign_proto(proto, name, val): | ||
| type (in recursive fashion). Lists become repeated fields/messages, dicts | ||
| become messages, and other types are assigned directly.""" | ||
| + is_repeated_field = hasattr(getattr(proto, name), 'extend') | ||
| + if is_repeated_field and not isinstance(val, list): | ||
| + val = [val] |
|
|
|
Okay, to look a little closer at this, let's enumerate the cases where repeated fields are actually used in layer parameters. I count:
In addition, we'll have soon A. N-D conv parameters Of these, 6 and 7 have "broadcast" behavior, where specifying one is the same as specifying the same value
The first behavior is not maintained by either implementation, while the second and third would be implemented by this PR. Given that (1) the distinction in these behaviors is not specified by protobuf, (2) neither implementation gives possibly "ideal" behavior in all cases, (3) the unary shorthand is widely accepted in the (I'm still unclear on how A is meant to work in the 1-dimensional case, though; shouldn't The patch looks good except documentation as noted. |
|
Thanks for the detailed discussion @longjon! I'll add a note on the behavior to the docstring.
For 1D conv, |
|
Thanks for the research and argument @longjon! I agree with everything here and think this is ready to merge following the docstring update by @jeffdonahue. Merge of #2049 can follow. |
jeffdonahue
added a commit
that referenced
this pull request
Sep 3, 2015
|
|
jeffdonahue |
50cbf01
|
jeffdonahue commentedAug 22, 2015
This makes NetSpec slightly friendlier by allowing single-element repeated fields to be specified without lists. I like this because it's similar to how the protobuf text format works: a single-element
repeatedfield can be specified just like anoptionalfield, and backwards compatibility is maintained when anoptionalfield is promoted to arepeatedfield. (To test this I modified an unrelated existing test -- happy to create a new one instead if that's desired.)