3
Eg @ s\ d dl mZmZ d dlmZmZmZmZ G dd deZ G dd deZ
G dd de
Zd S )
)core workspace)ClusterTask TaskGroup
WorkspaceTypec @ s e Zd ZdZdd ZdS )CompiledRunnablez? Wrapper for compiled runnable returned from session.compile() c C s || _ || _d S )N)obj
session_class)selfr r
r A/usr/local/lib64/python3.6/site-packages/caffe2/python/session.py__init__ s zCompiledRunnable.__init__N)__name__
__module____qualname____doc__r r r r r
r
s r c @ sz e Zd ZdZi Zdd Zdd ZedddZdd d
Z dd Z
d
d Zdd ZedddZ
dd Zdd Zdd ZdS )SessionaD
Allows to run Nets, ExecutionSteps, Plans, Tasks and TaskGroups.
A session can potentially run in multiple nodes concurrently.
Example:
from core import Net
from caffe2.python.task import Task, TaskGroup, WorkspaceType
net = Net('test1')
net.Add([net.Const(1), net.Const(2)])
net2 = net.Clone()
step = core.execution_step('step1', [net2])
with TaskGroup(WorkspaceType.GLOBAL) as init_tg:
with Node('node1'):
n1setup = net.Net('n1setup')
n1msg = n1setup.Const('Hello from node 1.')
Task(step=n1setup)
with TaskGroup() as private_tg:
with Node('node1'):
n1 = net.Net('n1')
n1.Print(n1msg, 0)
Task(step=n1)
with Node('node2'):
n2 = net.Net('n2')
n2.Print(n2.Const('Hello from node 2.'), 0)
Task(step=n2)
session = LocalSession()
session.run(net)
session.run(step)
session.run(init_tg)
session.run(private_tg)
Global Workspace:
At the beginning of the session, a global workspace is created and kept
alive for the duration of the session.
Private Workspace:
Tasks can be run either directly on the global workspace, or they can
instantiate a private child workspace that is released after each run.
Blob visibility:
Tasks running in different nodes in parallel will always run under
different workspaces, so it must be assumed that they won't be able to
access each other's blobs. Tasks running on the same node will follow
Workspace hierarchy rules: tasks running on separate private workspaces
will only be able to share blobs defined on a common parent Workspace.
c C s
d| _ d S )NT)_open)r r r r
r N s zSession.__init__c C s | j S )N)r )r r r r
is_openQ s zSession.is_openNc C sx t |tr2| |jks.tdd| j|jjf |S || jkrF| j| S t |tr|r|j r~|j |kstdj||j n||_ |}n|d krt
j}t|d}t |tr|j
| nt |tjr|j
t|d nt |tjr:t|j dkstt|j dkr$|j
t|j d d n|j
t|j d ntjd|}|j
t|d t| j||| d }|| j|<