D-X-Y / AutoDL-Projects

Automated deep learning algorithms implemented in PyTorch.
MIT License
1.57k stars 284 forks source link

Is it a problem when two edges of this node have the same j? #90

Closed prismformore closed 4 years ago

prismformore commented 4 years ago

https://github.com/D-X-Y/AutoDL-Projects/blob/befa6bcb00e0a8fcfba447d2a1348202759f58c9/lib/models/cell_infers/cells.py#L94

If I understand it correctly, in this snippet, when all the in_node in node point from the same node j, they will share the same node_str. When forward it will repeat the same operation and sum the results. It can be a problem.

      for in_node in node:
        name, j = in_node[0], in_node[1]
        node_str = '{:}<-{:}'.format(i+2, j)
        op = self.edges[ node_str ]
        clist.append( op(states[j]) )
D-X-Y commented 4 years ago

Thanks for the question. This is due to the premise of there is only a single edge between two nodes. If two "in_node" have the same "j", it is invalid.

prismformore commented 4 years ago

@D-X-Y Thank you for your timely reply. When searching, search cell doesn't force the searched genotype to follow this premise, but picks two edges from the results as selected edges:

  def genotype(self):
    def _parse(weights):
      gene = []
      for i in range(self._steps):
        edges = []
        for j in range(2+i):
          node_str = '{:}<-{:}'.format(i, j)
          ws = weights[ self.edge2index[node_str] ]
          for k, op_name in enumerate(self.op_names):
            if op_name == 'none': continue
            edges.append( (op_name, j, ws[k]) )
        edges = sorted(edges, key=lambda x: -x[-1])
        selected_edges = edges[:2]
        gene.append( tuple(selected_edges) )
      return gene

Maybe we can find the top 2 edges from different j here, or abandon the second in_node with same j in the infer cell.

Thank you!

D-X-Y commented 4 years ago

That is a very good point, and I agree with that. The genotype function follows the original DARTS implementation. I will add a NOTE at here to clarify the mismatch between search and re-train.

D-X-Y commented 4 years ago

Marked this problem as a TODO at here: https://github.com/D-X-Y/AutoDL-Projects/blob/master/lib/models/cell_searchs/search_model_darts_nasnet.py#L83

pomonam commented 3 years ago

BTW, what would be the correct behaviour in this case? Should we select top 2 from two different edges or change the assumption that they have to be from the different nodes.

D-X-Y commented 3 years ago

@pomonam I feel it is case-by-case and should be determined by yourself. Both are fine and can be supported by some reasons.