<jupyter_start><jupyter_text>3.2. Querying an encrypted model**protecting privacy and IP simultaneously**  Set up<jupyter_code># Import dependencies
import grid as gr
from grid import syft as sy
import torch as th
import skin_cancer_model_utils as scmu

# Ignore warnings
import warnings
warnings.filterwarnings('ignore')


# Hook torch
hook = sy.TorchHook(th)
me = hook.local_worker
me.is_client_worker = False
    
# Connect to nodes
grid_server = gr.WebsocketGridClient(hook, "http://localhost:3001", id="grid_server")
patient_server = gr.WebsocketGridClient(hook, "http://localhost:3000", id="patient_server")
hospital_server = gr.WebsocketGridClient(hook, "http://localhost:3002", id="hospital_server")
crypto_provider = gr.WebsocketGridClient(hook, "http://localhost:3003", id="crypto_provider")

grid_server.connect()
patient_server.connect()
hospital_server.connect()
crypto_provider.connect()

# Connect nodes to each other
gr.connect_all_nodes([grid_server, patient_server, hospital_server, crypto_provider])<jupyter_output>WARNING: Grid nodes publish datasets online and are for EXPERIMENTAL use only.Deploy nodes at your own risk. Do not use OpenGrid with any data/models you wish to keep private.

WARNING: Grid nodes publish datasets online and are for EXPERIMENTAL use only.Deploy nodes at your own risk. Do not use OpenGrid with any data/models you wish to keep private.

WARNING: Grid nodes publish datasets online and are for EXPERIMENTAL use only.Deploy nodes at your own risk. Do not use OpenGrid with any data/models you wish to keep private.

WARNING: Grid nodes publish datasets online and are for EXPERIMENTAL use only.Deploy nodes at your own risk. Do not use OpenGrid with any data/models you wish to keep private.<jupyter_text>Query model Get a copy of the encrypted model<jupyter_code>encrypted_model = grid_server.download_model("skin-cancer-model-encrypted")<jupyter_output><empty_output><jupyter_text>**Encrypted data for running through the model**<jupyter_code>data, target = scmu.get_data_sample()
x_sh = data.encrypt(patient_server, hospital_server, crypto_provider=crypto_provider)<jupyter_output><empty_output><jupyter_text>Run encrypted inference<jupyter_code>%%time
print(encrypted_model(x_sh).request_decryption(), target)<jupyter_output>tensor([[-0.1410, -0.0160]])
CPU times: user 2min 54s, sys: 1min 4s, total: 3min 58s
Wall time: 3min 52s
{'fraction_non_alphanumeric': 0.08648194794290512, 'fraction_numerical': 0.0163727959697733, 'mean_word_length': 6.687096774193549, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '501137', 'license': 'Apache-2.0', 'n_tokens_mistral': 753, 'n_tokens_neox': 720, 'n_words': 232, 'path': 'examples/Serving and Querying models on Grid/3.2. Querying an encrypted model.ipynb', 'repo_name': 'midokura-silvia/Grid', 'size': '2382'}