Skip to content

Commit

Permalink
Fix sphinx auto-discovery of decorated functions for MPCTensor (#167)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: fairinternal/CrypTen#167

Sphinx documentation fails to auto-discover docstrings for decorated methods. For example, `MPCTensor.pad()`.

This diff fixes Sphinx docstring auto-discovery by adding `functools.wraps` to the `mode` decorator for `MPCTensor`.

Reviewed By: knottb

Differential Revision: D18891067

fbshipit-source-id: 89e4c4a4083fa321be21ef69b73c5f2127710aba
  • Loading branch information
marksibrahim authored and facebook-github-bot committed Dec 10, 2019
1 parent 2094d75 commit a0b400c
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion crypten/mpc/mpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.

from functools import wraps

import crypten
import torch
from crypten.common.util import pool_reshape
Expand All @@ -19,6 +21,8 @@ def mode(ptype, inplace=False):
if inplace:

def function_wrapper(func):
# @wraps ensures docstrings are updated
@wraps(func)
def convert_wrapper(self, *args, **kwargs):
self._tensor = convert(self._tensor, ptype)
self.ptype = ptype
Expand All @@ -30,6 +34,8 @@ def convert_wrapper(self, *args, **kwargs):
else:

def function_wrapper(func):
# @wraps ensures docstrings are updated
@wraps(func)
def convert_wrapper(self, *args, **kwargs):
result = self.to(ptype)
return func(result, *args, **kwargs)
Expand Down Expand Up @@ -179,7 +185,7 @@ def dropout2d(self, p=0.5, training=True, inplace=False):
batched input is a 2D tensor :math:`\text{input}[i, j]`) of the input tensor).
Each channel will be zeroed out independently on every forward call with
probability :attr:`p` using samples from a Bernoulli distribution.
Args:
p: probability of a channel to be zeroed. Default: 0.5
training: apply dropout if is ``True``. Default: ``True``
Expand Down

0 comments on commit a0b400c

Please sign in to comment.