How to use to_module method in Testify

Best Python code snippet using Testify_python

test_feature_utils.py

Source:test_feature_utils.py Github

copy

Full Screen

1import numpy as np2import pytest3import torch4from ludwig.features import feature_utils5def test_ludwig_feature_dict():6 feature_dict = feature_utils.LudwigFeatureDict()7 to_module = torch.nn.Module()8 type_module = torch.nn.Module()9 feature_dict["to"] = to_module10 feature_dict["type"] = type_module11 assert iter(feature_dict) is not None12 assert next(feature_dict) is not None13 assert len(feature_dict) == 214 assert feature_dict.keys() == ["to", "type"]15 assert feature_dict.items() == [("to", to_module), ("type", type_module)]16 assert feature_dict["to"] == to_module17 feature_dict.update({"to_empty": torch.nn.Module()})18 assert len(feature_dict) == 319 assert [key for key in feature_dict] == ["to", "type", "to_empty"]20def test_ludwig_feature_dict_with_periods():21 feature_dict = feature_utils.LudwigFeatureDict()22 to_module = torch.nn.Module()23 feature_dict["to."] = to_module24 assert feature_dict.keys() == ["to."]25 assert feature_dict.items() == [("to.", to_module)]26 assert feature_dict["to."] == to_module27@pytest.mark.parametrize("sequence_type", [list, tuple, np.array])28def test_compute_token_probabilities(sequence_type):29 inputs = sequence_type(30 [31 [0.1, 0.2, 0.7],32 [0.3, 0.4, 0.3],33 [0.6, 0.3, 0.2],34 ]35 )36 token_probabilities = feature_utils.compute_token_probabilities(inputs)37 assert np.allclose(token_probabilities, [0.7, 0.4, 0.6])38def test_compute_sequence_probability():39 inputs = np.array([0.7, 0.4, 0.6])40 sequence_probability = feature_utils.compute_sequence_probability(41 inputs, max_sequence_length=2, return_log_prob=False42 )...

Full Screen

Full Screen

utils.py

Source:utils.py Github

copy

Full Screen

1import numpy as np2import torch3def assert_equal_model_outputs(input_var, model1, model2):4 model1.eval()5 model2.eval()6 model1_output = model1(input_var)7 model2_output = model2(input_var)8 assert torch.equal(model1_output, model2_output)9def assert_almost_equal_model_outputs(input_var, model1, model2):10 model1.eval()11 model2.eval()12 model1_output = model1(input_var)13 model2_output = model2(input_var)14 assert np.all(15 np.isclose(16 model1_output.data.numpy(),17 model2_output.data.numpy(),18 rtol=1e-04,19 atol=1e-06,20 )21 )22def copy_module_weights(from_module, to_module):23 to_module.weight.data.copy_(from_module.weight.data)24 to_module.bias.data.copy_(from_module.bias.data)25def assert_iterable_length_and_type(iterable, length, element_type):26 assert len(iterable) == length27 for element in iterable:28 assert isinstance(element, element_type)29def get_default_input_size_for_model(model_name):30 if (31 model_name == 'alexnet'32 or model_name.startswith('vgg')33 or model_name.startswith('squeezenet')34 ):35 return 224, 224...

Full Screen

Full Screen

connection.py

Source:connection.py Github

copy

Full Screen

1from collections import namedtuple2import asyncio3import logging4class Connection(namedtuple('Connection', ['from_module', 'from_output',5 'to_module', 'to_input',6 'key'])):7 async def establish(self):8 from_node, to_node = self.from_module.node, self.to_module.node9 connect = from_node.connect(self.from_module, self.from_output,10 self.to_module, self.to_input)11 set_key_from = from_node.set_key(self.from_module, self.from_output,12 self.key)13 set_key_to = to_node.set_key(self.to_module, self.to_input, self.key)14 await asyncio.gather(connect, set_key_from, set_key_to)15 logging.info('Connection from %s:%s on %s to %s:%s on %s established',16 self.from_module.name, self.from_output, from_node.name,...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Testify automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful