コード例 #1
0
    def translate_action(self, action: Action, to_framework: str) -> Action:
        """Uses threepio to perform command level translation given a specific action"""
        threepio = Threepio(self.plan.base_framework, to_framework, None)
        function_name = action.name.split(".")[-1]
        args = action.args if action.target is None else (action.target,
                                                          *action.args)
        translated_cmds = threepio.translate(
            Command(function_name, args, action.kwargs))

        actions = []
        for cmd in translated_cmds:
            new_action = action.copy()
            new_action.name = ".".join(cmd.attrs)
            new_action.args = tuple(cmd.args)
            new_action.kwargs = cmd.kwargs
            new_action.target = None
            actions.append(new_action)
        return actions
コード例 #2
0
ファイル: threepio.py プロジェクト: znbdata/PySyft
    def translate_action(self, action: ComputationAction, to_framework: str,
                         role: Role):
        """Uses threepio to perform command level translation given a specific action"""
        self._restore_placeholders(action)
        threepio = Threepio(self.plan.base_framework, to_framework, None)
        function_name = action.name.split(".")[-1]
        args = action.args if action.target is None else (action.target,
                                                          *action.args)
        translated_cmds = threepio.translate(
            Command(function_name, args, action.kwargs))

        if len(translated_cmds) > 1:
            return self.translate_multi_action(translated_cmds, action, role)

        for cmd in translated_cmds:
            role_action = (
                (".".join(cmd.attrs), None, tuple(cmd.args), cmd.kwargs),
                action.return_ids,
            )
            role.register_action(role_action, ComputationAction)
コード例 #3
0
import torch
from pythreepio.command import Command

abs = {
    "inputs": [Command("abs", [torch.Tensor([1, -2, 3, -4])], {})],
    "answers": [["tf", "abs"]],
}

abs_torch = {
    "inputs": [Command("abs", [torch.Tensor([1, -2, 3, -4])], {})],
    "answers": [[torch.Tensor([1, 2, 3, 4])]],
}

t1 = torch.Tensor([1, -2, 3, -4])
t2 = torch.Tensor([5, 5, 5, 5])
to_float = {
    "inputs": [Command("float", [t1], {})],
    "answers": [Command("cast", [t1, "float32"], {}, ["tf", "cast"])],
}

rtruediv = {
    "inputs": [Command("rtruediv", [t2, t1], {})],
    "answers": [Command("div", [t1, t2], {}, ["tf", "div"])],
}

reshape = {
    "inputs": [Command("reshape", [t1, [2, 2]], {})],
    "answers": [Command("reshape", [t1, [2, 2]], {}, ["reshape"])],
}
コード例 #4
0
ファイル: torch.py プロジェクト: pedroespindula/Threepio
import torch
import tensorflow as tf
from pythreepio.command import Command

abs = {
    "inputs": [Command("abs", [tf.constant([1, -2, 3, -4])], {})],
    "answers": [[tf.constant([1, 2, 3, 4])]],
}

add = {
    "inputs": [
        Command(
            "add", [tf.constant([[1, 0], [0, 1]]), tf.constant([[0, 1], [1, 0]])], {}
        )
    ],
    "answers": [[tf.constant([[1, 1], [1, 1]])]],
}

add2 = {
    "inputs": [
        Command(
            "__add__",
            [tf.constant([[1, 0], [0, 1]]), tf.constant([[0, 1], [1, 0]])],
            {},
        )
    ],
    "answers": [[tf.constant([[1, 1], [1, 1]])]],
}

matmul = {
    "inputs": [
コード例 #5
0
import torch
from pythreepio.command import Command

abs = {
    "inputs": [Command("abs", [torch.Tensor([1, -2, 3, -4])], {})],
    "answers": [[torch.Tensor([1, 2, 3, 4])]],
}