|
import pickle |
|
from safetensors import saveopen |
|
import datasets |
|
|
|
|
|
_DESCRIPTION = """\ |
|
Data sampled from an efficient-zero policy in the pong environment. The MCTS hidden state is included in the dataset. |
|
""" |
|
|
|
_HOMEPAGE = "https://github.com/opendilab/DI-engine" |
|
|
|
_LICENSE = "Apache-2.0" |
|
|
|
|
|
|
|
_BASE_URL = "https://huggingface.co/datasets/OpenDILabCommunity/Pong-v4-expert-MCTS/resolve/main" |
|
_URLS = { |
|
"Pong-v4-expert-MCTS": f"{_BASE_URL}/pong-v4-expert.safetensors", |
|
} |
|
|
|
|
|
class DecisionTransformerGymDataset(datasets.GeneratorBasedBuilder): |
|
|
|
VERSION = datasets.Version("0.0.1") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
BUILDER_CONFIGS = [ |
|
datasets.BuilderConfig( |
|
name="Pong-v4-expert-MCTS", |
|
version=VERSION, |
|
description="Data sampled from an efficient-zero policy in the pong environment", |
|
) |
|
] |
|
|
|
def _info(self): |
|
|
|
features = datasets.Features( |
|
{ |
|
"observation": datasets.Sequence(datasets.Sequence(datasets.Sequence(datasets.Value("uint8")))), |
|
"action": datasets.Value("int64"), |
|
"hidden_state": datasets.Sequence(datasets.Sequence(datasets.Sequence(datasets.Value("float32")))), |
|
|
|
} |
|
) |
|
|
|
return datasets.DatasetInfo( |
|
|
|
description=_DESCRIPTION, |
|
|
|
|
|
features=features, |
|
|
|
|
|
|
|
|
|
homepage=_HOMEPAGE, |
|
|
|
license=_LICENSE, |
|
) |
|
|
|
def _split_generators(self, dl_manager): |
|
urls = _URLS[self.config.name] |
|
data_dir = dl_manager.download_and_extract(urls) |
|
return [ |
|
datasets.SplitGenerator( |
|
name=datasets.Split.TRAIN, |
|
|
|
gen_kwargs={ |
|
"filepath": data_dir, |
|
"split": "train", |
|
}, |
|
) |
|
] |
|
|
|
|
|
def _generate_examples(self, filepath, split): |
|
data = {} |
|
with safe_open(filepath, framework="pt", device="cpu") as f: |
|
for key in f.keys(): |
|
data[key] = f.get_tensor(key) |
|
|
|
for idx in range(len(data['obs'])): |
|
yield idx, { |
|
'observation': data['obs'][idx], |
|
'action': data['actions'][idx], |
|
'hidden_state': data['hidden_state'][idx], |
|
} |
|
|