MCPcopy Create free account
hub / github.com/pytorch/pytorch / StartImmediate

Function StartImmediate

caffe2/python/workspace.py:592–639  ·  view source on GitHub ↗
(i_know=False)

Source from the content-addressed store, hash-verified

590
591
592def StartImmediate(i_know=False):
593 global _immediate_mode
594 global _immediate_root_folder
595 if IsImmediate():
596 # already in immediate mode. We will kill the previous one
597 # and start from fresh.
598 StopImmediate()
599 _immediate_mode = True
600 with WorkspaceGuard(_immediate_workspace_name):
601 _immediate_root_folder = tempfile.mkdtemp()
602 ResetWorkspace(_immediate_root_folder)
603 if i_know:
604 # if the user doesn't want to see the warning message, sure...
605 return
606 print("""
607 Enabling immediate mode in caffe2 python is an EXTREMELY EXPERIMENTAL
608 feature and may very easily go wrong. This is because Caffe2 uses a
609 declarative way of defining operators and models, which is essentially
610 not meant to run things in an interactive way. Read the following carefully
611 to make sure that you understand the caveats.
612
613 (1) You need to make sure that the sequences of operators you create are
614 actually runnable sequentially. For example, if you create an op that takes
615 an input X, somewhere earlier you should have already created X.
616
617 (2) Caffe2 immediate uses one single workspace, so if the set of operators
618 you run are intended to be under different workspaces, they will not run.
619 To create boundaries between such use cases, you can call FinishImmediate()
620 and StartImmediate() manually to flush out everything no longer needed.
621
622 (3) Underlying objects held by the immediate mode may interfere with your
623 normal run. For example, if there is a leveldb that you opened in immediate
624 mode and did not close, your main run will fail because leveldb does not
625 support double opening. Immediate mode may also occupy a lot of memory esp.
626 on GPUs. Call FinishImmediate() as soon as possible when you no longer
627 need it.
628
629 (4) Immediate is designed to be slow. Every immediate call implicitly
630 creates a temp operator object, runs it, and destroys the operator. This
631 slow-speed run is by design to discourage abuse. For most use cases other
632 than debugging, do NOT turn on immediate mode.
633
634 (5) If there is anything FATAL happening in the underlying C++ code, the
635 immediate mode will immediately (pun intended) cause the runtime to crash.
636
637 Thus you should use immediate mode with extra care. If you still would
638 like to, have fun [https://xkcd.com/149/].
639 """)
640
641
642def StopImmediate():

Callers

nothing calls this directly

Calls 4

IsImmediateFunction · 0.85
StopImmediateFunction · 0.85
WorkspaceGuardFunction · 0.85
ResetWorkspaceFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…