@autotest() def test_flow_matmul_with_random_data(test_case): k = random(1, 6) x = random_pytorch_tensor(ndim=2, dim1=k) y = random_pytorch_tensor(ndim=2, dim0=k) z = torch.matmul(x, y) return z
def _to(self, annotation): if self.annotation is not None: return if hasattr(annotation, "__origin__"): # PyTorch _size_2_t and similar types are defined by type variables, # leading to unexpected __args__ and __origin__ # # >>> _size_2_t = Union[T, Tuple[T, T]][int] # >>> _size_2_t.__origin__ # typing.Union[~T, typing.Tuple[~T, ~T]] # # So recreate a new annotation object by repr and eval # # >>> _size_2_t # typing.Union[int, typing.Tuple[int, int]] # >>> _size_2_t_new = eval(repr(annotation)) # >>> _size_2_t_new.__origin__ # typing.Union annotation = eval(repr(annotation)) self.annotation = annotation
def _generate(self, annotation): if hasattr(annotation, "__origin__"): if annotation.__origin__ is Union: x = random_util.choice(annotation.__args__) return self._generate(x) if annotation.__origin__ is Tuple or annotation.__origin__ is py_tuple: return [self._generate(x) for x in annotation.__args__] else: raise NotImplementedError( f"Not implemented annotation {annotation} in random, type(annotation.__origin__) is {type(annotation.__origin__)}" )
low, high = self.low.value(), self.high.value()
if annotation == int: val = int(rng.integers(low, high)) elif annotation == float: val = float(rng.random() * (high - low) + low) elif annotation == bool: val = random_util.choice([True, False]) else: raise NotImplementedError( f"Not implemented annotation {annotation} in random" ) return val
def autotest( n=20, auto_backward=True, rtol=0.0001, atol=1e-05, check_graph=True, check_allclose=True, ): verbose = os.getenv("ONEFLOW_TEST_VERBOSE") is not None
def deco(f): @functools.wraps(f) def new_f(test_case): nonlocal n loop_limit = n * 20 loop = 0 while n > 0: clear_note_fake_program() if loop > loop_limit: raise ValueError("autotest stuck in an endless loop!") dual_modules_to_test.clear() dual_objects_to_test.clear() try: global testing testing = True global testing_graph if check_graph: testing_graph = True res = f(test_case) testing = False testing_graph = False except (PyTorchDoesNotSupportError, BothDoNotSupportError) as e: if verbose: print(f"{f.__name__}") print(e) loop += 1 continue if res is not None: if not isinstance(res, collections.abc.Sequence): res = [res] func_outputs = res for x in res: if auto_backward: if isinstance(x.pytorch, torch_original.Tensor): call_tensor_id.append(id(x.pytorch)) x.sum().backward() dual_objects_to_test.append(x) for x in dual_modules_to_test: for key in x.pytorch.state_dict().keys(): if key not in x.oneflow.state_dict().keys(): warnings.warn(f"oneflow module don't have `{key}`") continue vis_parameters[key] = x.pytorch.state_dict()[key] dual_objects_to_test.append( GetDualObject( "unused", getattr(x.pytorch, key), getattr(x.oneflow, key), ) ) call_tensor_id.append(id(getattr(x.pytorch, key))) dual_objects_to_test.append( GetDualObject( "unused", getattr(x.pytorch, key).grad, getattr(x.oneflow, key).grad, ) ) call_tensor_id.append(id(getattr(x.pytorch, key).grad))
for x in dual_objects_to_test: if ( isinstance(x.pytorch, torch_original.Tensor) and id(x.pytorch) not in call_tensor_id ): vis_tensor.append(x.pytorch) # check eager for x in dual_objects_to_test: if check_allclose: test_case.assertTrue(check_equality(x, rtol=rtol, atol=atol), x) if verbose: print(f"{f.__name__} test eager passed.")
Nacos /nɑ:kəʊs/ 是 Dynamic Naming and Configuration Service 的首字母简称,一个易于构建 AI Agent 应用的动态服务发现、配置管理和AI智能体管理平台。Nacos 致力于帮助您发现、配置和管理微服务及AI智能体应用。Nacos 提供了一组简单易用的特性集,帮助您快速实现动态服务发现、服务配置、服务元数据、流量管理。Nacos 帮助您更敏捷和容易地构建、交付和管理微服务平台。
Sublime Text
Sublime Text具有漂亮的用户界面和强大的功能,例如代码缩略图,Python的插件,代码段等。还可自定义键绑定,菜单和工具栏。Sublime Text 的主要功能包括:拼写检查,书签,完整的 Python API , Goto 功能,即时项目切换,多选择,多窗口等等。Sublime Text 是一个跨平台的编辑器,同时支持Windows、Linux、Mac OS X等操作系统。