max_stars_repo_path
stringlengths 4
245
| max_stars_repo_name
stringlengths 7
115
| max_stars_count
int64 101
368k
| id
stringlengths 2
8
| content
stringlengths 6
1.03M
|
---|---|---|---|---|
unittest_reinvent/running_modes/transfer_learning_tests/test_link_invent_transfer_learning.py | lilleswing/Reinvent-1 | 183 | 12799943 | <gh_stars>100-1000
import shutil
import unittest
import os
from running_modes.configurations import TransferLearningLoggerConfig, GeneralConfigurationEnvelope
from running_modes.configurations.transfer_learning.link_invent_learning_rate_configuration import \
LinkInventLearningRateConfiguration
from running_modes.configurations.transfer_learning.link_invent_transfer_learning_configuration import \
LinkInventTransferLearningConfiguration
from running_modes.constructors.transfer_learning_mode_constructor import TransferLearningModeConstructor
from running_modes.utils import set_default_device_cuda
from running_modes.enums.logging_mode_enum import LoggingModeEnum
from running_modes.enums.running_mode_enum import RunningModeEnum
from reinvent_models.model_factory.enums.model_type_enum import ModelTypeEnum
from unittest_reinvent.fixtures.paths import MAIN_TEST_PATH, SMILES_SET_LINK_INVENT_PATH, LINK_INVENT_PRIOR_PATH
from unittest_reinvent.fixtures.utils import count_empty_files
class TestLinkInventTransferLearning(unittest.TestCase):
def setUp(self):
set_default_device_cuda()
lm_enum = LoggingModeEnum()
rm_enum = RunningModeEnum()
mt_enum = ModelTypeEnum()
self.workfolder = os.path.join(MAIN_TEST_PATH, mt_enum.LINK_INVENT + rm_enum.TRANSFER_LEARNING)
if not os.path.isdir(self.workfolder):
os.makedirs(self.workfolder)
self.log_dir = os.path.join(self.workfolder, "test_log")
log_config = TransferLearningLoggerConfig(logging_path=self.log_dir, recipient=lm_enum.LOCAL,
job_name="test_job")
self.lr_config = LinkInventLearningRateConfiguration()
self.parameters = LinkInventTransferLearningConfiguration(empty_model=LINK_INVENT_PRIOR_PATH,
output_path=self.workfolder,
input_smiles_path=SMILES_SET_LINK_INVENT_PATH,
validation_smiles_path=None,
num_epochs=2,
sample_size=10,
learning_rate=self.lr_config)
self.general_config = GeneralConfigurationEnvelope(model_type=mt_enum.LINK_INVENT, logging=vars(log_config),
run_type=rm_enum.TRANSFER_LEARNING, version="3.0",
parameters=vars(self.parameters))
self.runner = TransferLearningModeConstructor(self.general_config)
def tearDown(self):
if os.path.isdir(self.workfolder):
shutil.rmtree(self.workfolder)
def _model_saved_and_logs_exist(self):
self.assertTrue(os.path.isfile(os.path.join(self.workfolder, self.parameters.model_file_name)))
self.assertTrue(os.path.isdir(self.log_dir))
self.assertEqual(count_empty_files(self.log_dir), 0)
def test_no_validation(self):
self.parameters.validation_smiles_path = None
self.runner.run()
self._model_saved_and_logs_exist()
def test_with_validation(self):
self.parameters.validation_smiles_path = SMILES_SET_LINK_INVENT_PATH
self.runner.run()
self._model_saved_and_logs_exist()
|
src/schemathesis/runner/impl/__init__.py | gluhar2006/schemathesis | 659 | 12799970 | <gh_stars>100-1000
from .core import BaseRunner
from .solo import SingleThreadASGIRunner, SingleThreadRunner, SingleThreadWSGIRunner
from .threadpool import ThreadPoolASGIRunner, ThreadPoolRunner, ThreadPoolWSGIRunner
|
tfx/orchestration/portable/execution_watcher.py | avelez93/tfx | 1,813 | 12799989 | <filename>tfx/orchestration/portable/execution_watcher.py
# Copyright 2021 Google LLC. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""This module provides a gRPC service for updating remote job info to MLMD."""
from concurrent import futures
from typing import Optional
from absl import logging
import grpc
from tfx.orchestration import metadata
from tfx.proto.orchestration import execution_watcher_pb2
from tfx.proto.orchestration import execution_watcher_pb2_grpc
from ml_metadata.proto import metadata_store_pb2
def generate_service_stub(
address: str,
creds: Optional[grpc.ChannelCredentials] = None,
) -> execution_watcher_pb2_grpc.ExecutionWatcherServiceStub:
"""Generates a gRPC service stub for a given server address."""
channel = grpc.secure_channel(
address, creds) if creds else grpc.insecure_channel(address)
return execution_watcher_pb2_grpc.ExecutionWatcherServiceStub(channel)
class ExecutionWatcher(
execution_watcher_pb2_grpc.ExecutionWatcherServiceServicer):
"""A gRPC service server for updating remote job info to MLMD.
Attributes:
local_address: Local network address to the server.
address: Remote network address to the server, same as local_address if not
configured.
"""
def __init__(self,
port: int,
mlmd_connection: metadata.Metadata,
execution: metadata_store_pb2.Execution,
address: Optional[str] = None,
creds: Optional[grpc.ServerCredentials] = None):
"""Initializes the gRPC server.
Args:
port: Which port the service will be using.
mlmd_connection: ML metadata connection.
execution: The MLMD Execution to keep track of.
address: Remote address used to contact the server. Should be formatted as
an ipv4 or ipv6 address in the format `address:port`. If left as
None, server will use local address.
creds: gRPC server credentials. If left as None, server will use an
insecure port.
"""
super().__init__()
self._port = port
self._address = address
self._creds = creds
self._mlmd_connection = mlmd_connection
self._server = self._create_server()
if not execution.HasField('id'):
raise ValueError(
'execution id must be set to be tracked by ExecutionWatcher.')
self._execution = execution
def UpdateExecutionInfo(
self, request: execution_watcher_pb2.UpdateExecutionInfoRequest,
context: grpc.ServicerContext
) -> execution_watcher_pb2.UpdateExecutionInfoResponse:
"""Updates the `custom_properties` field of Execution object in MLMD."""
logging.info('Received request to update execution info: updates %s, '
'execution_id %s', request.updates, request.execution_id)
if request.execution_id != self._execution.id:
context.set_code(grpc.StatusCode.NOT_FOUND)
context.set_details(
'Execution with given execution_id not tracked by server: '
f'{request.execution_id}')
return execution_watcher_pb2.UpdateExecutionInfoResponse()
for key, value in request.updates.items():
self._execution.custom_properties[key].CopyFrom(
value)
# Only the execution is needed
with self._mlmd_connection as m:
m.store.put_executions((self._execution,))
return execution_watcher_pb2.UpdateExecutionInfoResponse()
def _create_server(self):
"""Creates a gRPC server and add `self` on to it."""
result = grpc.server(futures.ThreadPoolExecutor())
execution_watcher_pb2_grpc.add_ExecutionWatcherServiceServicer_to_server(
self, result)
if self._creds is None:
result.add_insecure_port(self.local_address)
else:
result.add_secure_port(self.local_address, self._creds)
return result
@property
def local_address(self) -> str:
# Local network address to the server.
return f'localhost:{self._port}'
@property
def address(self) -> str:
return self._address or self.local_address
def start(self):
"""Starts the server."""
self._server.start()
def stop(self):
"""Stops the server."""
self._server.stop(grace=None)
|