Skip to content

Commit

Permalink
add fp16 and upstream states for tree pipeline (#80)
Browse files Browse the repository at this point in the history
  • Loading branch information
annasun28 authored Oct 11, 2023
1 parent b07447a commit 5aabaf1
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
12 changes: 9 additions & 3 deletions simuleval/agents/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,17 +269,20 @@ def push_impl(
module: GenericAgent,
segment: Segment,
states: Optional[Dict[GenericAgent, AgentStates]],
upstream_states: Dict[int, AgentStates],
):
# DFS over the tree
children = self.module_dict[module]
if len(children) == 0: # leaf node
module.push(segment, states[module])
return []

segment = module.pushpop(segment, states[module])
segment = module.pushpop(segment, states[module], upstream_states)
assert len(upstream_states) not in upstream_states
upstream_states[len(upstream_states)] = states[module]

for child in children:
self.push_impl(child, segment, states)
self.push_impl(child, segment, states, upstream_states)

def pushpop(
self,
Expand All @@ -300,8 +303,11 @@ def push(
states = {module: None for module in self.module_dict}
else:
assert len(states) == len(self.module_dict)

if upstream_states is None:
upstream_states = {}

self.push_impl(self.source_module, segment, states)
self.push_impl(self.source_module, segment, states, upstream_states)

def pop(
self, states: Optional[Dict[GenericAgent, AgentStates]] = None
Expand Down
3 changes: 3 additions & 0 deletions simuleval/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,9 @@ def general_parser():
parser.add_argument(
"--device", type=str, default="cpu", help="Device to run the model."
)
parser.add_argument(
"--fp16", action="store_true", default=False, help="Use fp16."
)
return parser


Expand Down
4 changes: 2 additions & 2 deletions simuleval/utils/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ def build_system_args(

args = parser.parse_args(cli_argument_list(config_dict))

logger.info(f"System will run on device: {args.device}.")
system.to(args.device)
logger.info(f"System will run on device: {args.device}. fp16: {args.fp16}")
system.to(args.device, fp16=args.fp16)

args.source_type = system.source_type
args.target_type = system.target_type
Expand Down

0 comments on commit 5aabaf1

Please sign in to comment.