Skip to content

Fix subset of linting rules #4119

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

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -152,4 +152,3 @@ load(
)

nccl_configure(name = "local_config_nccl")

12 changes: 9 additions & 3 deletions tensorflow_serving/apis/model_service_pb2.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,25 @@
# python -m grpc.tools.protoc --python_out=. --grpc_python_out=. -I. tensorflow_serving/apis/model_service.proto

import sys

_b=sys.version_info[0]<3 and (lambda x:x) or (lambda x:x.encode('latin1'))
from google.protobuf import descriptor as _descriptor
from google.protobuf import descriptor_pb2
from google.protobuf import message as _message
from google.protobuf import reflection as _reflection
from google.protobuf import symbol_database as _symbol_database
from google.protobuf import descriptor_pb2

# @@protoc_insertion_point(imports)

_sym_db = _symbol_database.Default()


from tensorflow_serving.apis import get_model_status_pb2 as tensorflow__serving_dot_apis_dot_get__model__status__pb2
from tensorflow_serving.apis import model_management_pb2 as tensorflow__serving_dot_apis_dot_model__management__pb2
from tensorflow_serving.apis import (
get_model_status_pb2 as tensorflow__serving_dot_apis_dot_get__model__status__pb2,
)
from tensorflow_serving.apis import (
model_management_pb2 as tensorflow__serving_dot_apis_dot_model__management__pb2,
)

DESCRIPTOR = _descriptor.FileDescriptor(
name='tensorflow_serving/apis/model_service.proto',
Expand Down
37 changes: 18 additions & 19 deletions tensorflow_serving/apis/model_service_pb2_grpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,16 @@

import grpc

from tensorflow_serving.apis import get_model_status_pb2 as tensorflow__serving_dot_apis_dot_get__model__status__pb2
from tensorflow_serving.apis import model_management_pb2 as tensorflow__serving_dot_apis_dot_model__management__pb2
from tensorflow_serving.apis import (
get_model_status_pb2 as tensorflow__serving_dot_apis_dot_get__model__status__pb2,
)
from tensorflow_serving.apis import (
model_management_pb2 as tensorflow__serving_dot_apis_dot_model__management__pb2,
)


class ModelServiceStub(object):
"""ModelService provides methods to query and update the state of the server,
e.g. which models/versions are being served.
"""
class ModelServiceStub:
"""ModelService provides methods to query and update the state of the server, e.g. which models/versions are being served."""

def __init__(self, channel):
"""Constructor.
Expand All @@ -50,25 +52,22 @@ def __init__(self, channel):
)


class ModelServiceServicer(object):
"""ModelService provides methods to query and update the state of the server,
e.g. which models/versions are being served.
"""
class ModelServiceServicer:
"""ModelService provides methods to query and update the state of the server e.g. which models/versions are being served."""

def GetModelStatus(self, request, context):
"""Gets status of model. If the ModelSpec in the request does not specify
version, information about all versions of the model will be returned. If
the ModelSpec in the request does specify a version, the status of only
that version will be returned.
def GetModelStatus(self, request, context): # noqa: ARG002
"""Gets status of model.

If the ModelSpec in the request does not specify version, information about all versions of the model will be returned. If the ModelSpec in the request does specify a version, the status of only that version will be returned.
"""
context.set_code(grpc.StatusCode.UNIMPLEMENTED)
context.set_details('Method not implemented!')
raise NotImplementedError('Method not implemented!')

def HandleReloadConfigRequest(self, request, context):
"""Reloads the set of served models. The new config supersedes the old one,
so if a model is omitted from the new config it will be unloaded and no
longer served.
def HandleReloadConfigRequest(self, request, context): # noqa: ARG002
"""Reloads the set of served models.

The new config supersedes the old one, so if a model is omitted from the new config it will be unloaded and no longer served.
"""
context.set_code(grpc.StatusCode.UNIMPLEMENTED)
context.set_details('Method not implemented!')
Expand Down
25 changes: 18 additions & 7 deletions tensorflow_serving/apis/prediction_service_pb2.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,34 @@
# source: tensorflow_serving/apis/prediction_service.proto

import sys

_b=sys.version_info[0]<3 and (lambda x:x) or (lambda x:x.encode('latin1'))
from google.protobuf import descriptor as _descriptor
from google.protobuf import descriptor_pb2
from google.protobuf import message as _message
from google.protobuf import reflection as _reflection
from google.protobuf import symbol_database as _symbol_database
from google.protobuf import descriptor_pb2

# @@protoc_insertion_point(imports)

_sym_db = _symbol_database.Default()


from tensorflow_serving.apis import classification_pb2 as tensorflow__serving_dot_apis_dot_classification__pb2
from tensorflow_serving.apis import get_model_metadata_pb2 as tensorflow__serving_dot_apis_dot_get__model__metadata__pb2
from tensorflow_serving.apis import inference_pb2 as tensorflow__serving_dot_apis_dot_inference__pb2
from tensorflow_serving.apis import predict_pb2 as tensorflow__serving_dot_apis_dot_predict__pb2
from tensorflow_serving.apis import regression_pb2 as tensorflow__serving_dot_apis_dot_regression__pb2

from tensorflow_serving.apis import (
classification_pb2 as tensorflow__serving_dot_apis_dot_classification__pb2,
)
from tensorflow_serving.apis import (
get_model_metadata_pb2 as tensorflow__serving_dot_apis_dot_get__model__metadata__pb2,
)
from tensorflow_serving.apis import (
inference_pb2 as tensorflow__serving_dot_apis_dot_inference__pb2,
)
from tensorflow_serving.apis import (
predict_pb2 as tensorflow__serving_dot_apis_dot_predict__pb2,
)
from tensorflow_serving.apis import (
regression_pb2 as tensorflow__serving_dot_apis_dot_regression__pb2,
)

DESCRIPTOR = _descriptor.FileDescriptor(
name='tensorflow_serving/apis/prediction_service.proto',
Expand Down
61 changes: 33 additions & 28 deletions tensorflow_serving/apis/prediction_service_pb2_grpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,27 @@
# python -m grpc.tools.protoc --python_out=. --grpc_python_out=. -I. tensorflow_serving/apis/prediction_service.proto
import grpc

from tensorflow_serving.apis import classification_pb2 as tensorflow__serving_dot_apis_dot_classification__pb2
from tensorflow_serving.apis import get_model_metadata_pb2 as tensorflow__serving_dot_apis_dot_get__model__metadata__pb2
from tensorflow_serving.apis import inference_pb2 as tensorflow__serving_dot_apis_dot_inference__pb2
from tensorflow_serving.apis import predict_pb2 as tensorflow__serving_dot_apis_dot_predict__pb2
from tensorflow_serving.apis import regression_pb2 as tensorflow__serving_dot_apis_dot_regression__pb2
from tensorflow_serving.apis import (
classification_pb2 as tensorflow__serving_dot_apis_dot_classification__pb2,
)
from tensorflow_serving.apis import (
get_model_metadata_pb2 as tensorflow__serving_dot_apis_dot_get__model__metadata__pb2,
)
from tensorflow_serving.apis import (
inference_pb2 as tensorflow__serving_dot_apis_dot_inference__pb2,
)
from tensorflow_serving.apis import (
predict_pb2 as tensorflow__serving_dot_apis_dot_predict__pb2,
)
from tensorflow_serving.apis import (
regression_pb2 as tensorflow__serving_dot_apis_dot_regression__pb2,
)


class PredictionServiceStub(object):
"""open source marker; do not remove
PredictionService provides access to machine-learned models loaded by
model_servers.
class PredictionServiceStub:
"""PredictionService provides access to machine-learned models loaded by model_servers.

open source marker; do not remove
"""

def __init__(self, channel):
Expand Down Expand Up @@ -64,43 +74,38 @@ def __init__(self, channel):
)


class PredictionServiceServicer(object):
"""open source marker; do not remove
PredictionService provides access to machine-learned models loaded by
model_servers.
class PredictionServiceServicer:
"""PredictionService provides access to machine-learned models loaded by model_servers.

open source marker; do not remove
"""

def Classify(self, request, context):
"""Classify.
"""
def Classify(self, request, context): # noqa: ARG002
"""Classify."""
context.set_code(grpc.StatusCode.UNIMPLEMENTED)
context.set_details('Method not implemented!')
raise NotImplementedError('Method not implemented!')

def Regress(self, request, context):
"""Regress.
"""
def Regress(self, request, context): # noqa: ARG002
"""Regress."""
context.set_code(grpc.StatusCode.UNIMPLEMENTED)
context.set_details('Method not implemented!')
raise NotImplementedError('Method not implemented!')

def Predict(self, request, context):
"""Predict -- provides access to loaded TensorFlow model.
"""
def Predict(self, request, context): # noqa: ARG002
"""Predict -- provides access to loaded TensorFlow model."""
context.set_code(grpc.StatusCode.UNIMPLEMENTED)
context.set_details('Method not implemented!')
raise NotImplementedError('Method not implemented!')

def MultiInference(self, request, context):
"""MultiInference API for multi-headed models.
"""
def MultiInference(self, request, context): # noqa: ARG002
"""MultiInference API for multi-headed models."""
context.set_code(grpc.StatusCode.UNIMPLEMENTED)
context.set_details('Method not implemented!')
raise NotImplementedError('Method not implemented!')

def GetModelMetadata(self, request, context):
"""GetModelMetadata - provides access to metadata for loaded models.
"""
def GetModelMetadata(self, request, context): # noqa: ARG002
"""GetModelMetadata - provides access to metadata for loaded models."""
context.set_code(grpc.StatusCode.UNIMPLEMENTED)
context.set_details('Method not implemented!')
raise NotImplementedError('Method not implemented!')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,23 @@
# ==============================================================================

import tensorflow.compat.v1 as tf

FLAGS = tf.app.flags.FLAGS

tf.app.flags.DEFINE_string("output_dir", "/tmp/matrix_half_plus_two/1",
"The directory where to write SavedModel files.")


def _generate_saved_model_for_matrix_half_plus_two(export_dir):
"""Creates SavedModel for half plus two model that accepts batches of
3*3 matrices.
The model divides all elements in each matrix by 2 and adds 2 to them.
So, for one input matrix [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
the result will be [[2.5, 3, 3.5], [4, 4.5, 5], [5.5, 6, 6.5]].
Args:
export_dir: The directory where to write SavedModel files.
"""
"""Creates SavedModel for half plus two model that accepts batches of 3*3 matrices.

The model divides all elements in each matrix by 2 and adds 2 to them.
So, for one input matrix [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
the result will be [[2.5, 3, 3.5], [4, 4.5, 5], [5.5, 6, 6.5]].

Args:
export_dir: The directory where to write SavedModel files.
"""
builder = tf.saved_model.builder.SavedModelBuilder(export_dir)
with tf.Session() as session:
x = tf.placeholder(tf.float32, shape=[None, 3, 3], name="x")
Expand Down
10 changes: 4 additions & 6 deletions tensorflow_serving/example/mnist_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,16 @@
mnist_client.py --num_tests=100 --server=localhost:9000
"""

from __future__ import print_function

import sys
import threading

import grpc
import mnist_input_data
import numpy
import tensorflow as tf

from tensorflow_serving.apis import predict_pb2
from tensorflow_serving.apis import prediction_service_pb2_grpc
import mnist_input_data

from tensorflow_serving.apis import predict_pb2, prediction_service_pb2_grpc

tf.compat.v1.app.flags.DEFINE_integer(
'concurrency', 1, 'maximum number of concurrent inference requests')
Expand All @@ -48,7 +45,7 @@
FLAGS = tf.compat.v1.app.flags.FLAGS


class _ResultCounter(object):
class _ResultCounter:
"""Counter for the prediction results."""

def __init__(self, num_tests, concurrency):
Expand Down Expand Up @@ -92,6 +89,7 @@ def _create_rpc_callback(label, result_counter):
Args:
label: The correct label for the predicted example.
result_counter: Counter for the prediction result.

Returns:
The callback function.
"""
Expand Down
28 changes: 12 additions & 16 deletions tensorflow_serving/example/mnist_input_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

"""Functions for downloading and reading MNIST data."""

from __future__ import print_function

import gzip
import os
Expand All @@ -42,7 +41,7 @@ def maybe_download(filename, work_directory):
if not os.path.exists(filepath):
filepath, _ = urllib.request.urlretrieve(SOURCE_URL + filename, filepath)
statinfo = os.stat(filepath)
print('Successfully downloaded %s %d bytes.' % (filename, statinfo.st_size))
print(f'Successfully downloaded {filename} {statinfo.st_size} bytes.')
return filepath


Expand All @@ -53,20 +52,19 @@ def _read32(bytestream):

def extract_images(filename):
"""Extract the images into a 4D uint8 numpy array [index, y, x, depth]."""
print('Extracting %s' % filename)
print(f'Extracting {filename}')
with gzip.open(filename) as bytestream:
magic = _read32(bytestream)
if magic != 2051:
raise ValueError(
'Invalid magic number %d in MNIST image file: %s' %
(magic, filename))
f'Invalid magic number {magic} in MNIST image file: {filename}'
)
num_images = _read32(bytestream)
rows = _read32(bytestream)
cols = _read32(bytestream)
buf = bytestream.read(rows * cols * num_images)
data = numpy.frombuffer(buf, dtype=numpy.uint8)
data = data.reshape(num_images, rows, cols, 1)
return data
return data.reshape(num_images, rows, cols, 1)


def dense_to_one_hot(labels_dense, num_classes=10):
Expand All @@ -80,13 +78,13 @@ def dense_to_one_hot(labels_dense, num_classes=10):

def extract_labels(filename, one_hot=False):
"""Extract the labels into a 1D uint8 numpy array [index]."""
print('Extracting %s' % filename)
print(f'Extracting {filename}')
with gzip.open(filename) as bytestream:
magic = _read32(bytestream)
if magic != 2049:
raise ValueError(
'Invalid magic number %d in MNIST label file: %s' %
(magic, filename))
f'Invalid magic number {magic} in MNIST label file: {filename}'
)
num_items = _read32(bytestream)
buf = bytestream.read(num_items)
labels = numpy.frombuffer(buf, dtype=numpy.uint8)
Expand All @@ -95,19 +93,17 @@ def extract_labels(filename, one_hot=False):
return labels


class DataSet(object):
class DataSet:
"""Class encompassing test, validation and training MNIST data set."""

def __init__(self, images, labels, fake_data=False, one_hot=False):
"""Construct a DataSet. one_hot arg is used only if fake_data is true."""

if fake_data:
self._num_examples = 10000
self.one_hot = one_hot
else:
assert images.shape[0] == labels.shape[0], (
'images.shape: %s labels.shape: %s' % (images.shape,
labels.shape))
f'images.shape: {images.shape} labels.shape: {labels.shape}')
self._num_examples = images.shape[0]

# Convert shape from [num examples, rows, columns, depth]
Expand Down Expand Up @@ -157,7 +153,7 @@ def next_batch(self, batch_size, fake_data=False):
self._epochs_completed += 1
# Shuffle the data
perm = numpy.arange(self._num_examples)
numpy.random.shuffle(perm)
numpy.random.default_rng().shuffle(perm)
self._images = self._images[perm]
self._labels = self._labels[perm]
# Start next epoch
Expand All @@ -171,7 +167,7 @@ def next_batch(self, batch_size, fake_data=False):
def read_data_sets(train_dir, fake_data=False, one_hot=False):
"""Return training, validation and testing data sets."""

class DataSets(object):
class DataSets:
pass

data_sets = DataSets()
Expand Down
Loading