def pipeline(self, default=steps.standard, config=None): if self.options['--scalar']: resources = scalar_pipeline.resources else: resources = standard_pipeline.resources all_steps = self.options['pipeline'] pos = [p for p in all_steps if not isinstance(p, Not)] neg = {p.value for p in all_steps if isinstance(p, Not)} if not pos: pos = default final = [p for p in pos if p not in neg] pdef = PipelineDefinition(resources=resources, steps={p._name: p for p in final}) opts = self.options['opts'] if opts and steps.opt not in final: raise Exception('Optimizations can only be applied if the' ' opt step is in the pipeline') elif opts: pdef = pdef.configure({'opt.opts': Merge(opts)}) if callable(config): pdef = config(pdef) elif config: pdef = pdef.configure(config) return pdef.make()
def op_pipeline(): return PipelineDefinition( addp=OpStep.partial(op=lambda p, x: p + x, param=1), mulp=OpStep.partial(op=lambda p, x: p * x, param=2), neg=OpStep.partial(op=lambda p, x: -x), square=OpStep.partial(op=lambda p, x: x * x), )
def op_pipeline(): return PipelineDefinition( resources=dict(param=2), steps=dict( addp=OpStep.partial(op=lambda p, x: p + x, param=1), mulp=OpResourceStep.partial(op=lambda p, x: p * x), neg=OpStep.partial(op=lambda p, x: -x), square=OpStep.partial(op=lambda p, x: x * x), ))
def grad_wrap(graph, argspec): mg = GradOperation(graph, wrt=['*'], dout_parameter=True, always_return_tuple=True) sig = mg.make_signature(argspec) g = mg.generate_graph(sig) return {'graph': g} grad_pipeline = PipelineDefinition( resources=standard_resources, parse=steps.step_parse, resolve=steps.step_resolve, infer=steps.step_infer, specialize=steps.step_specialize, opt=steps.step_debug_opt, validate=steps.step_validate, export=steps.step_debug_export, ) def test_GradTester(): def f(x, y): return x / y def df(x, y, dz): return dz / y, -dz * x / (y * y) arglist = ( (7.3, 4.2),
mg = GradOperation(graph, wrt=['*'], dout_parameter=True, always_return_tuple=True) sig = mg.make_signature(argspec) g = mg.generate_graph(sig) return {'graph': g} grad_pipeline = PipelineDefinition( resources=standard_resources, parse=steps.step_parse, resolve=steps.step_resolve, infer=steps.step_infer, specialize=steps.step_specialize, opt=steps.step_debug_opt, validate=steps.step_validate, export=steps.step_debug_export, ).configure({ 'resources.operation_whitelist': grad_whitelist, 'resources.validate_abstract': grad_validate_abstract }) def test_GradTester(): def f(x, y): return x / y def df(x, y, dz): return dz / y, -dz * x / (y * y)