-
Notifications
You must be signed in to change notification settings - Fork 5.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[xdoctest][task cleanup 376~381] reformat example code with google style #57853
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,6 +46,7 @@ class Categorical(distribution.Distribution): | |
Examples: | ||
.. code-block:: python | ||
|
||
>>> # doctest: +REQUIRES(env:DISTRIBUTED) | ||
>>> import paddle | ||
>>> from paddle.distribution import Categorical | ||
|
||
|
@@ -64,7 +65,7 @@ class Categorical(distribution.Distribution): | |
>>> cat = Categorical(x) | ||
>>> cat2 = Categorical(y) | ||
|
||
>>> # doctest: +SKIP | ||
>>> # doctest: +SKIP('`paddle.distribution` can not run in xdoctest') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 并不是说直接 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 咋说呢,其实我是照着 |
||
>>> paddle.seed(1000) # on CPU device | ||
>>> print(cat.sample([2,3])) | ||
Tensor(shape=[2, 3], dtype=int64, place=Place(cpu), stop_gradient=True, | ||
|
@@ -134,6 +135,7 @@ def sample(self, shape): | |
Examples: | ||
.. code-block:: python | ||
|
||
>>> # doctest: +REQUIRES(env:DISTRIBUTED) | ||
>>> import paddle | ||
>>> from paddle.distribution import Categorical | ||
|
||
|
@@ -191,6 +193,7 @@ def kl_divergence(self, other): | |
Examples: | ||
.. code-block:: python | ||
|
||
>>> # doctest: +REQUIRES(env:DISTRIBUTED) | ||
>>> import paddle | ||
>>> from paddle.distribution import Categorical | ||
|
||
|
@@ -245,6 +248,7 @@ def entropy(self): | |
Examples: | ||
.. code-block:: python | ||
|
||
>>> # doctest: +REQUIRES(env:DISTRIBUTED) | ||
>>> import paddle | ||
>>> from paddle.distribution import Categorical | ||
|
||
|
@@ -289,6 +293,7 @@ def probs(self, value): | |
Examples: | ||
.. code-block:: python | ||
|
||
>>> # doctest: +REQUIRES(env:DISTRIBUTED) | ||
>>> import paddle | ||
>>> from paddle.distribution import Categorical | ||
|
||
|
@@ -336,6 +341,7 @@ def log_prob(self, value): | |
Examples: | ||
.. code-block:: python | ||
|
||
>>> # doctest: +REQUIRES(env:DISTRIBUTED) | ||
>>> import paddle | ||
>>> from paddle.distribution import Categorical | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1140,7 +1140,7 @@ class Model: | |
... | ||
... model = paddle.Model(net) | ||
... optim = paddle.optimizer.SGD(learning_rate=1e-3, parameters=model.parameters()) | ||
... | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 为什么要删? |
||
... amp_configs = { | ||
... "level": "O1", | ||
... "custom_white_list": {'conv2d'}, | ||
|
@@ -1150,15 +1150,15 @@ class Model: | |
... paddle.nn.CrossEntropyLoss(), | ||
... paddle.metric.Accuracy(), | ||
... amp_configs=amp_configs) | ||
... | ||
|
||
... transform = T.Compose([T.Transpose(), T.Normalize([127.5], [127.5])]) | ||
... data = paddle.vision.datasets.MNIST(mode='train', transform=transform) | ||
... model.fit(data, epochs=2, batch_size=32, verbose=1) | ||
... | ||
>>> # mixed precision training is only supported on GPU now. | ||
>>> if paddle.is_compiled_with_cuda(): | ||
... run_example_code() | ||
... | ||
|
||
""" | ||
|
||
def __init__(self, network, inputs=None, labels=None): | ||
|
@@ -1228,7 +1228,7 @@ def train_batch(self, inputs, labels=None, update=True): | |
... nn.Linear(784, 200), | ||
... nn.Tanh(), | ||
... nn.Linear(200, 10)) | ||
... | ||
|
||
>>> input = InputSpec([None, 784], 'float32', 'x') | ||
>>> label = InputSpec([None, 1], 'int64', 'label') | ||
>>> model = paddle.Model(net, input, label) | ||
|
@@ -1282,7 +1282,7 @@ def eval_batch(self, inputs, labels=None): | |
... nn.Linear(784, 200), | ||
... nn.Tanh(), | ||
... nn.Linear(200, 10)) | ||
... | ||
|
||
>>> input = InputSpec([None, 784], 'float32', 'x') | ||
>>> label = InputSpec([None, 1], 'int64', 'label') | ||
>>> model = paddle.Model(net, input, label) | ||
|
@@ -1337,7 +1337,7 @@ def predict_batch(self, inputs): | |
... nn.Tanh(), | ||
... nn.Linear(200, 10), | ||
... nn.Softmax()) | ||
... | ||
|
||
>>> model = paddle.Model(net, input, label) | ||
>>> model.prepare() | ||
>>> data = paddle.rand((1, 784), dtype="float32") | ||
|
@@ -1467,7 +1467,7 @@ def load(self, path, skip_mismatch=False, reset_optimizer=False): | |
... nn.Tanh(), | ||
... nn.Linear(200, 10), | ||
... nn.Softmax()), input) | ||
... | ||
|
||
>>> model.save('checkpoint/test') | ||
>>> model.load('checkpoint/test') | ||
|
||
|
@@ -1558,7 +1558,7 @@ def parameters(self, *args, **kwargs): | |
... nn.Linear(784, 200), | ||
... nn.Tanh(), | ||
... nn.Linear(200, 10)), input) | ||
... | ||
|
||
>>> params = model.parameters() | ||
>>> print(params) | ||
[Parameter containing: | ||
|
@@ -1835,7 +1835,7 @@ def fit( | |
>>> dynamic = True | ||
>>> if not dynamic: | ||
... paddle.enable_static() | ||
... | ||
|
||
>>> transform = T.Compose([T.Transpose(), | ||
... T.Normalize([127.5], [127.5])]) | ||
>>> train_dataset = MNIST(mode='train', transform=transform) | ||
|
@@ -1858,7 +1858,7 @@ def fit( | |
... epochs=2, | ||
... batch_size=64, | ||
... save_dir='mnist_checkpoint') | ||
... | ||
|
||
2. An example use DataLoader, batch size and shuffle is set in | ||
DataLoader. | ||
|
||
|
@@ -1873,7 +1873,7 @@ def fit( | |
>>> dynamic = True | ||
>>> if not dynamic: | ||
... paddle.enable_static() | ||
... | ||
|
||
>>> transform = T.Compose([T.Transpose(), | ||
... T.Normalize([127.5], [127.5])]) | ||
>>> train_dataset = MNIST(mode='train', transform=transform) | ||
|
@@ -1882,7 +1882,7 @@ def fit( | |
>>> val_dataset = MNIST(mode='test', transform=transform) | ||
>>> val_loader = paddle.io.DataLoader(val_dataset, | ||
... batch_size=64) | ||
... | ||
|
||
>>> input = InputSpec([None, 1, 28, 28], 'float32', 'image') | ||
>>> label = InputSpec([None, 1], 'int64', 'label') | ||
|
||
|
@@ -1898,7 +1898,7 @@ def fit( | |
... val_loader, | ||
... epochs=2, | ||
... save_dir='mnist_checkpoint') | ||
... | ||
|
||
""" | ||
assert train_data is not None, "train_data must be given!" | ||
|
||
|
@@ -2154,16 +2154,16 @@ def predict( | |
... def __init__(self, mode, return_label=True): | ||
... super().__init__(mode=mode) | ||
... self.return_label = return_label | ||
... | ||
|
||
... def __getitem__(self, idx): | ||
... img = np.reshape(self.images[idx], [1, 28, 28]) | ||
... if self.return_label: | ||
... return img, np.array(self.labels[idx]).astype('int64') | ||
... return img | ||
... | ||
|
||
... def __len__(self): | ||
... return len(self.images) | ||
... | ||
|
||
>>> test_dataset = MnistDataset(mode='test', return_label=False) | ||
|
||
>>> # imperative mode | ||
|
@@ -2399,7 +2399,7 @@ def summary(self, input_size=None, dtype=None): | |
>>> optim = paddle.optimizer.Adam(learning_rate=0.001, parameters=model.parameters()) | ||
>>> model.prepare(optim, paddle.nn.CrossEntropyLoss()) | ||
>>> params_info = model.summary() | ||
>>> # doctest: +SKIP | ||
>>> # doctest: +SKIP('`paddle.static` can not run in xdoctest') | ||
>>> print(params_info) | ||
--------------------------------------------------------------------------- | ||
Layer (type) Input Shape Output Shape Param # | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
376-381 是添加 SKIP reason,这些额外修改的原因是?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
那我恢复?