PySyft: dimension out of range

  1. I have a model that I am Testing, this model has undergone training. I have a sy.Virtualworker that I send a tensor to. I send the model to this virtual worker. I get the error IndexError: Dimension out of range (expected to be in range of [-1, 0], but got 1)

  2. I have looked at other errors with this similar error, however, this might have an issue with what i’m doing with the pysyft material.

  3. the goal is to get a prediction from the model based on the input. I believed the input to be of similar dimensions to what the model would work with.

  4. I either have an issue with how im dealing with the pysyft materia. As I have worked with this code successfully when doing a non-pysyft version and have seen the intended results.

full error list:

Traceback (most recent call last):
  File "C:\Users\OMEGA-Money\AppData\Roaming\Python\Python36\site-packages\syft\frameworks\torch\tensors\interpreters\native.py", line 333, in handle_func_command
    cmd, args_, kwargs_, return_args_type=True
  File "C:\Users\OMEGA-Money\AppData\Roaming\Python\Python36\site-packages\syft\generic\frameworks\hook\hook_args.py", line 157, in unwrap_args_from_function
    new_args = hook_args(args_)
  File "C:\Users\OMEGA-Money\AppData\Roaming\Python\Python36\site-packages\syft\generic\frameworks\hook\hook_args.py", line 356, in <lambda>
    return lambda x: f(lambdas, x)
  File "C:\Users\OMEGA-Money\AppData\Roaming\Python\Python36\site-packages\syft\generic\frameworks\hook\hook_args.py", line 535, in three_fold
    lambdas[1](args_[1], **kwargs),
  File "C:\Users\OMEGA-Money\AppData\Roaming\Python\Python36\site-packages\syft\generic\frameworks\hook\hook_args.py", line 331, in <lambda>
    else lambda i: forward_func[type(i)](i)
  File "C:\Users\OMEGA-Money\AppData\Roaming\Python\Python36\site-packages\syft\frameworks\torch\hook\hook_args.py", line 30, in <lambda>
    else (_ for _ in ()).throw(PureFrameworkTensorFoundError),
  File "C:\Users\OMEGA-Money\AppData\Roaming\Python\Python36\site-packages\syft\frameworks\torch\hook\hook_args.py", line 30, in <genexpr>
    else (_ for _ in ()).throw(PureFrameworkTensorFoundError),
syft.exceptions.PureFrameworkTensorFoundError
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "B:\tools and software\PyCharm 2020.1\plugins\python\helpers\pydev\_pydev_bundle\pydev_umd.py", line 197, in runfile
    pydev_imports.execfile(filename, global_vars, local_vars)  # execute the script
  File "B:\tools and software\PyCharm 2020.1\plugins\python\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc)
  File "B:/projects/GRA/FederatedLearningAnalysis/anomaly-detection/PyTroch_singleworker_combined_train_test.py", line 266, in <module>
    app.run(main)
  File "B:\tools and software\Anaconda\envs\pysyft-pytorch\lib\site-packages\absl\app.py", line 299, in run
    _run_main(main, args)
  File "B:\tools and software\Anaconda\envs\pysyft-pytorch\lib\site-packages\absl\app.py", line 250, in _run_main
    sys.exit(main(argv))
  File "B:/projects/GRA/FederatedLearningAnalysis/anomaly-detection/PyTroch_singleworker_combined_train_test.py", line 261, in main
    tr=tr, df_malicious=load_mal_data(), features=features)
  File "B:/projects/GRA/FederatedLearningAnalysis/anomaly-detection/PyTroch_singleworker_combined_train_test.py", line 131, in test_with_data
    Y_pred = model.predict(torch.from_numpy(X_test_scaled).float())
  File "B:/projects/GRA/FederatedLearningAnalysis/anomaly-detection/PyTroch_singleworker_combined_train_test.py", line 204, in predict
    x_pred = self.model(x)
  File "B:\tools and software\Anaconda\envs\pysyft-pytorch\lib\site-packages\torch\nn\modules\module.py", line 532, in __call__
    result = self.forward(*input, **kwargs)
  File "B:/projects/GRA/FederatedLearningAnalysis/anomaly-detection/PyTroch_singleworker_combined_train_test.py", line 183, in forward
    x = torch.tanh(self.fc1(x))
  File "B:\tools and software\Anaconda\envs\pysyft-pytorch\lib\site-packages\torch\nn\modules\module.py", line 532, in __call__
    result = self.forward(*input, **kwargs)
  File "B:\tools and software\Anaconda\envs\pysyft-pytorch\lib\site-packages\torch\nn\modules\linear.py", line 87, in forward
    return F.linear(input, self.weight, self.bias)
  File "C:\Users\OMEGA-Money\AppData\Roaming\Python\Python36\site-packages\syft\generic\frameworks\hook\hook.py", line 336, in overloaded_func
    response = handle_func_command(command)
  File "C:\Users\OMEGA-Money\AppData\Roaming\Python\Python36\site-packages\syft\frameworks\torch\tensors\interpreters\native.py", line 343, in handle_func_command
    response = new_type.handle_func_command(new_command)
  File "C:\Users\OMEGA-Money\AppData\Roaming\Python\Python36\site-packages\syft\generic\pointers\object_pointer.py", line 213, in handle_func_command
    response = owner.send_command(location, cmd_name=cmd, args_=args_, kwargs_=kwargs_)
  File "C:\Users\OMEGA-Money\AppData\Roaming\Python\Python36\site-packages\syft\workers\base.py", line 626, in send_command
    ret_val = self.send_msg(message, location=recipient)
  File "C:\Users\OMEGA-Money\AppData\Roaming\Python\Python36\site-packages\syft\workers\base.py", line 274, in send_msg
    bin_response = self._send_msg(bin_message, location)
  File "C:\Users\OMEGA-Money\AppData\Roaming\Python\Python36\site-packages\syft\workers\virtual.py", line 16, in _send_msg
    return location._recv_msg(message)
  File "C:\Users\OMEGA-Money\AppData\Roaming\Python\Python36\site-packages\syft\workers\virtual.py", line 20, in _recv_msg
    return self.recv_msg(message)
  File "C:\Users\OMEGA-Money\AppData\Roaming\Python\Python36\site-packages\syft\workers\base.py", line 310, in recv_msg
    response = self._message_router[type(msg)](msg)
  File "C:\Users\OMEGA-Money\AppData\Roaming\Python\Python36\site-packages\syft\workers\base.py", line 451, in execute_tensor_command
    return self.execute_computation_action(cmd.action)
  File "C:\Users\OMEGA-Money\AppData\Roaming\Python\Python36\site-packages\syft\workers\base.py", line 514, in execute_computation_action
    response = command(*args_, **kwargs_)
  File "C:\Users\OMEGA-Money\AppData\Roaming\Python\Python36\site-packages\syft\generic\frameworks\hook\hook.py", line 336, in overloaded_func
    response = handle_func_command(command)
  File "C:\Users\OMEGA-Money\AppData\Roaming\Python\Python36\site-packages\syft\frameworks\torch\tensors\interpreters\native.py", line 367, in handle_func_command
    response = cls._get_response(cmd, args_, kwargs_)
  File "C:\Users\OMEGA-Money\AppData\Roaming\Python\Python36\site-packages\syft\frameworks\torch\tensors\interpreters\native.py", line 401, in _get_response
    response = command_method(*args_, **kwargs_)
  File "B:\tools and software\Anaconda\envs\pysyft-pytorch\lib\site-packages\torch\nn\functional.py", line 1370, in linear
    ret = torch.addmm(bias, input, weight.t())
  File "C:\Users\OMEGA-Money\AppData\Roaming\Python\Python36\site-packages\syft\generic\frameworks\hook\hook.py", line 336, in overloaded_func
    response = handle_func_command(command)
  File "C:\Users\OMEGA-Money\AppData\Roaming\Python\Python36\site-packages\syft\frameworks\torch\tensors\interpreters\native.py", line 367, in handle_func_command
    response = cls._get_response(cmd, args_, kwargs_)
  File "C:\Users\OMEGA-Money\AppData\Roaming\Python\Python36\site-packages\syft\frameworks\torch\tensors\interpreters\native.py", line 401, in _get_response
    response = command_method(*args_, **kwargs_)
IndexError: Dimension out of range (expected to be in range of [-1, 0], but got 1)

CODE bits:

    def predict(self, x):
        x = x.send('testing')
        self.model.send(x.location)
        x_pred = self.model(x)
        mse = np.mean(np.power(x.get().data.numpy() - x_pred.get().data.numpy(), 2), axis=1)
        y_pred = mse > self.threshold
        return y_pred.astype(int)

CODE 2:

X_test = df.drop(columns=["malicious"]).values
    X_test_scaled = scaler.transform(X_test)
    Y_test = df["malicious"]
    Y_pred = model.predict(torch.from_numpy(X_test_scaled).float())

If more code is needed, just say.

cc @ptrblck do you know who would be the best person to answer PySyft questions?

@RavikantSingh is a member of OpenMined and might be able to help. I cannot find the user account of Andrew Trask (and unsure, if he’s active in this board).

1 Like