MCPcopy Index your code
hub / github.com/modelscope/modelscope / _forward

Function _forward

modelscope/utils/regress_test_utils.py:518–557  ·  view source on GitHub ↗
(self, *args, **kwargs)

Source from the content-addressed store, hash-verified

516 keep_tensors=False):
517
518 def _forward(self, *args, **kwargs):
519 ret = self.forward_origin(*args, **kwargs)
520 if keep_tensors:
521 args = numpify_tensor_nested(detach_tensor_nested(args))
522 kwargs = numpify_tensor_nested(detach_tensor_nested(kwargs))
523 output = numpify_tensor_nested(detach_tensor_nested(ret))
524 else:
525 args = {
526 'sum':
527 numpify_tensor_nested(
528 detach_tensor_nested(args), reduction='sum'),
529 'mean':
530 numpify_tensor_nested(
531 detach_tensor_nested(args), reduction='mean'),
532 }
533 kwargs = {
534 'sum':
535 numpify_tensor_nested(
536 detach_tensor_nested(kwargs), reduction='sum'),
537 'mean':
538 numpify_tensor_nested(
539 detach_tensor_nested(kwargs), reduction='mean'),
540 }
541 output = {
542 'sum':
543 numpify_tensor_nested(
544 detach_tensor_nested(ret), reduction='sum'),
545 'mean':
546 numpify_tensor_nested(
547 detach_tensor_nested(ret), reduction='mean'),
548 }
549
550 io_json[name] = {
551 'input': {
552 'args': args,
553 'kwargs': kwargs,
554 },
555 'output': output,
556 }
557 return ret
558
559 if not restore and not hasattr(module, 'forward_origin'):
560 module.forward_origin, module.forward = module.forward, type(

Callers

nothing calls this directly

Calls 2

numpify_tensor_nestedFunction · 0.85
detach_tensor_nestedFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…