2021-06-03 10:08:17 +02:00
|
|
|
#####################################################
|
|
|
|
# Copyright (c) Xuanyi Dong [GitHub D-X-Y], 2021.03 #
|
|
|
|
#############################################################
|
|
|
|
# Borrow the idea of https://github.com/arogozhnikov/einops #
|
|
|
|
#############################################################
|
|
|
|
import torch
|
|
|
|
import torch.nn as nn
|
|
|
|
import torch.nn.functional as F
|
|
|
|
|
|
|
|
import math
|
|
|
|
from typing import Optional, Callable
|
|
|
|
|
|
|
|
from xautodl import spaces
|
2021-06-08 14:42:16 +02:00
|
|
|
from .misc_utils import ParsedExpression
|
2021-06-03 10:08:17 +02:00
|
|
|
from .super_module import SuperModule
|
|
|
|
from .super_module import IntSpaceType
|
|
|
|
from .super_module import BoolSpaceType
|
|
|
|
|
|
|
|
|
2021-06-03 10:24:09 +02:00
|
|
|
class SuperReArrange(SuperModule):
|
2021-06-03 10:08:17 +02:00
|
|
|
"""Applies the rearrange operation."""
|
|
|
|
|
|
|
|
def __init__(self, pattern, **axes_lengths):
|
2021-06-03 10:24:09 +02:00
|
|
|
super(SuperReArrange, self).__init__()
|
2021-06-03 10:08:17 +02:00
|
|
|
|
|
|
|
self._pattern = pattern
|
|
|
|
self._axes_lengths = axes_lengths
|
2021-06-08 14:42:16 +02:00
|
|
|
axes_lengths = tuple(sorted(self._axes_lengths.items()))
|
|
|
|
# Perform initial parsing of pattern and provided supplementary info
|
|
|
|
# axes_lengths is a tuple of tuples (axis_name, axis_length)
|
|
|
|
left, right = pattern.split("->")
|
|
|
|
left = ParsedExpression(left)
|
|
|
|
right = ParsedExpression(right)
|
|
|
|
|
|
|
|
import pdb
|
|
|
|
|
|
|
|
pdb.set_trace()
|
|
|
|
print("-")
|
2021-06-03 10:08:17 +02:00
|
|
|
|
|
|
|
@property
|
|
|
|
def abstract_search_space(self):
|
|
|
|
root_node = spaces.VirtualNode(id(self))
|
|
|
|
return root_node
|
|
|
|
|
|
|
|
def forward_candidate(self, input: torch.Tensor) -> torch.Tensor:
|
2021-06-08 14:42:16 +02:00
|
|
|
self.forward_raw(input)
|
2021-06-03 10:08:17 +02:00
|
|
|
|
|
|
|
def forward_raw(self, input: torch.Tensor) -> torch.Tensor:
|
2021-06-08 14:42:16 +02:00
|
|
|
import pdb
|
|
|
|
|
|
|
|
pdb.set_trace()
|
2021-06-03 10:08:17 +02:00
|
|
|
raise NotImplementedError
|
|
|
|
|
|
|
|
def extra_repr(self) -> str:
|
|
|
|
params = repr(self._pattern)
|
|
|
|
for axis, length in self._axes_lengths.items():
|
|
|
|
params += ", {}={}".format(axis, length)
|
2021-06-08 14:42:16 +02:00
|
|
|
return "{:}".format(params)
|