Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
alf
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Philipp Sauer
alf
Commits
bbc666d2
Unverified
Commit
bbc666d2
authored
2 years ago
by
Haichao Zhang
Committed by
GitHub
2 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Add flatten to create_environment; fix time_step stack issue (#1425)
parent
47117679
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
alf/environments/parallel_environment.py
+1
-1
1 addition, 1 deletion
alf/environments/parallel_environment.py
alf/environments/utils.py
+4
-1
4 additions, 1 deletion
alf/environments/utils.py
with
5 additions
and
2 deletions
alf/environments/parallel_environment.py
+
1
−
1
View file @
bbc666d2
...
...
@@ -182,7 +182,7 @@ class ParallelAlfEnvironment(alf_environment.AlfEnvironment):
self
.
_time_step_with_env_info_spec
,
*
time_steps
)
else
:
stacked
=
nest
.
fast_map_structure
(
lambda
*
arrays
:
torch
.
stack
(
arrays
),
*
time_steps
)
lambda
*
arrays
:
numpy
.
stack
(
arrays
),
*
time_steps
)
stacked
=
nest
.
map_structure
(
lambda
x
:
torch
.
as_tensor
(
x
,
device
=
'
cpu
'
),
stacked
)
if
alf
.
get_default_device
()
==
"
cuda
"
:
...
...
This diff is collapsed.
Click to expand it.
alf/environments/utils.py
+
4
−
1
View file @
bbc666d2
...
...
@@ -61,6 +61,7 @@ def create_environment(env_name='CartPole-v0',
env_load_fn
=
suite_gym
.
load
,
num_parallel_environments
=
30
,
nonparallel
=
False
,
flatten
=
True
,
seed
=
None
,
batched_wrappers
=
()):
"""
Create a batched environment.
...
...
@@ -77,6 +78,8 @@ def create_environment(env_name='CartPole-v0',
num_parallel_environments (int): num of parallel environments
nonparallel (bool): force to create a single env in the current
process. Used for correctly exposing game gin confs to tensorboard.
flatten (bool): whether to use flatten action and time_steps during
communication to reduce overhead.
seed (None|int): random number seed for environment. A random seed is
used if None.
batched_wrappers (Iterable): a list of wrappers which can wrap batched
...
...
@@ -119,7 +122,7 @@ def create_environment(env_name='CartPole-v0',
alf_env
=
parallel_environment
.
ParallelAlfEnvironment
(
[
functools
.
partial
(
env_load_fn
,
env_name
)]
*
num_parallel_environments
,
flatten
=
True
)
flatten
=
flatten
)
if
seed
is
None
:
alf_env
.
seed
([
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment