Securely serializing/loading untrusted pytorch models?

username: turian
cooked: <p>I am currently organizing a NeuroIPS competition, in which participants might be submitting pytorch models to our evaluation server for the leaderboard.</p>
<p><strong>Is there a secure way of serializing/loading untrusted pytorch models?</strong></p>
<p>Are there alternatively to pickle, which can be insecure? Is there a pytorch model format we can insist upon that is secure?</p>
<p>I believe that ONNX + tensorflow use protobuf, which avoids the security issues of pickling.</p>

username: albanD
cooked: <p>There has been some discussion around it: <a href="https://github.com/pytorch/pytorch/issues/52596" class="inline-onebox">pickle is a security issue · Issue #52596 · pytorch/pytorch · GitHub</a><br>
But I don’t think there is a simple solution.</p>
<p>I guess you can require them to export their model to onnx. But that might lead to some restrictions as not all PyTorch models are able to go through onnx <img src="https://discuss.pytorch.org/images/emoji/apple/confused.png?v=9" title=":confused:" class="emoji" alt=":confused:"></p>

username: ptrblck
cooked: <p>Additionally to what <a class="mention" href="/u/alband">@albanD</a> said, I think you could try to secure your environment by e.g. running submissions in a container (singularity or docker) without any permissions, which could affect your bare metal systems. Of course a system is never 100% secure and in the worst case users might try to escape the container, but you could at least reduce the probability of malicious code doing harm.</p>
<p>EDIT: I’m unsure about the background of the competition, but in the past (a couple of years ago) I’ve hosted a small closed competition on Kaggle. Maybe it’s still possible and would fit your use case?</p>
<p>EDIT2: You could also think about just accepting raw text data (as csv files) containing the validation predictions instead of the models.</p>

username: turian
cooked: <p><a class="mention" href="/u/ptrblck">@ptrblck</a> thanks for the feedback. What sort of performance issues will I encounter versus bare-metal? My main experience has been loading from disk is slower.</p>
<p>Right now we are leaning towards keeping the evaluation tasks secret, thus we don’t want to share the evaluation data until the competition is over. Curious about what code you have for that.</p>
<p>Docker is also useful because I can disable networking, which mitigates the risk anyone tries to exfiltrate the blinded evaluation data. Not really familiar with Singularity, what are the pros and cons versus using Docker for a competition like this.</p>
<p>Let me know if you want to hear more about the challenge offline. My email is <a href="mailto:username@gmail.com">username@gmail.com</a></p>

username: ptrblck
cooked: <aside class="quote no-group" data-username="turian" data-post="4" data-topic="119744">
<div class="title">
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/turian/48/30217_2.png" class="avatar"> turian:</div>
<blockquote>
<p>What sort of performance issues will I encounter versus bare-metal? My main experience has been loading from disk is slower.</p>
</blockquote>
</aside>
<p>I’m not sure, if I understand the question correctly. What would you mean from disk? Do you mean the performance difference between the Kaggle kernels with their (free) GPU runtime vs. a bare metal machine? If so, I cannot comment on the performance of the free Kaggle kernels and am not sure what is being used currently.</p>
<aside class="quote no-group" data-username="turian" data-post="4" data-topic="119744">
<div class="title">
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/turian/48/30217_2.png" class="avatar"> turian:</div>
<blockquote>
<p>Right now we are leaning towards keeping the evaluation tasks secret, thus we don’t want to share the evaluation data until the competition is over. Curious about what code you have for that.</p>
</blockquote>
</aside>
<p>Kaggle is using an approach where the users submit the predictions and will get a score based on a secret part of the submission samples. E.g. the score of only 10% of the submission will be reported while internally the score of the entire submission will be stored. This is known as the “public” and “private” leaderboard. Since number of submissions are limited, users (usually) cannot brute force the private leaderboard samples. However, as so often, users might find a data leak which could allow them to somehow get more information about the public/private split, but issues with data leaks are sometimes hard to predict. <img src="https://discuss.pytorch.org/images/emoji/apple/wink.png?v=12" title=":wink:" class="emoji" alt=":wink:" loading="lazy" width="20" height="20"></p>
<aside class="quote no-group" data-username="turian" data-post="4" data-topic="119744">
<div class="title">
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/turian/48/30217_2.png" class="avatar"> turian:</div>
<blockquote>
<p>Docker is also useful because I can disable networking, which mitigates the risk anyone tries to exfiltrate the blinded evaluation data. Not really familiar with Singularity, what are the pros and cons versus using Docker for a competition like this.</p>
</blockquote>
</aside>
<p>I’m not deeply familiar with Singularity either, but have heard that it can be “more secure”, so you would need to check some comparisons conline or blog posts etc.</p>

username: turian
cooked: <aside class="quote no-group" data-username="ptrblck" data-post="5" data-topic="119744">
<div class="title">
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/ptrblck/48/1823_2.png" class="avatar"> ptrblck:</div>
<blockquote>
<p>I’m not sure, if I understand the question correctly. What would you mean from disk? Do you mean the performance difference between the Kaggle kernels with their (free) GPU runtime vs. a bare metal machine? If so, I cannot comment on the performance of the free Kaggle kernels and am not sure what is being used currently.</p>
</blockquote>
</aside>
<p>In Docker, I’ve found that shared mounts sometimes have slow (particularly write) performance. So if the dataset lives outside Docker, reads might be slow?</p>
<aside class="quote no-group">
<blockquote>
<p>Kaggle is using an approach where the users submit the predictions and will get a score based on a secret part of the submission samples.</p>
</blockquote>
</aside>
<p>But participants are provided the input data? We would prefer to avoid this.</p>
<p>I will look up Singularity</p>

username: ptrblck
cooked: <p>OK, if participants don’t have the input data, I assume you are setting up machines for them to train and evaluate their models?</p>
<aside class="quote no-group" data-username="turian" data-post="6" data-topic="119744">
<div class="title">
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/turian/48/30217_2.png" class="avatar"> turian:</div>
<blockquote>
<p>In Docker, I’ve found that shared mounts sometimes have slow (particularly write) performance. So if the dataset lives outside Docker, reads might be slow?</p>
</blockquote>
</aside>
<p>I haven’t seen this issue in docker and am heavily using it for my workloads.<br>
A slow data loading can of course be met, if you are using a mounted folder from a network drive, but that’s not depending on docker but the network speed, so I would recommend to copy the data to a fast local storage.</p>