Error loading RLLib offline data using ray.data.read_json

When loading RLLib offline data using ray.data.read_json the following error occurs: “ValueError: number sections must be larger than 0.”

Here is the code snippet that loads the data:

  dataset = ray.data.read_json(
      self.offline_data_info['train_dir'],
      parallelism=2,
      ray_remote_args=dict(num_cpus=1)
  )

Here is the stacktrace:
File “/home/stefan/anaconda3/envs/py38_ray2/lib/python3.8/site-packages/ray/data/read_api.py”, line 524, in read_json
return read_datasource(
File “/home/stefan/anaconda3/envs/py38_ray2/lib/python3.8/site-packages/ray/data/read_api.py”, line 268, in read_datasource
requested_parallelism, min_safe_parallelism, read_tasks = ray.get(
File “/home/stefan/anaconda3/envs/py38_ray2/lib/python3.8/site-packages/ray/_private/client_mode_hook.py”, line 105, in wrapper
return func(*args, **kwargs)
File “/home/stefan/anaconda3/envs/py38_ray2/lib/python3.8/site-packages/ray/_private/worker.py”, line 2275, in get
raise value.as_instanceof_cause()
ray.exceptions.RayTaskError(ValueError): ray::_get_read_tasks() (pid=656667, ip=10.0.0.60)
File “/home/stefan/anaconda3/envs/py38_ray2/lib/python3.8/site-packages/ray/data/read_api.py”, line 1143, in _get_read_tasks
reader.get_read_tasks(requested_parallelism),
File “/home/stefan/anaconda3/envs/py38_ray2/lib/python3.8/site-packages/ray/data/datasource/file_based_datasource.py”, line 440, in get_read_tasks
np.array_split(paths, parallelism), np.array_split(file_sizes, parallelism)
File “<array_function internals>”, line 5, in array_split
File “/home/stefan/anaconda3/envs/py38_ray2/lib/python3.8/site-packages/numpy/lib/shape_base.py”, line 778, in array_split
raise ValueError(‘number sections must be larger than 0.’) from None
ValueError: number sections must be larger than 0.

Here is a really small sample of the RLLib offline dataset that can be used to replicate this error:
{“type”: “SampleBatch”, “t”: [0, 1, 2, 3], “eps_id”: [0, 0, 0, 0], “agent_index”: [0, 0, 0, 0], “obs”: “BCJNGGhAsAEAAAAAAACnCwEAAGGABZWlAQABAPMZjBJudW1weS5jb3JlLm51bWVyaWOUjAtfZnJvbWJ1ZmZlcpSTlCiWMC8AQAAA3EIGAAgCAPARMzOzP6rPKT8zMxdDZ81DQZqZQUKtH+9APKV7QfOqv0AsAPsMQxzBQ+fI40C+9pVA3AK4P5ALMD8AAIBCAADIUAD/BsA/0GROP83MF0NK0FFBAAA+QswV5UwAECBgQWgAClAAD0wAJQACAASYAAQIAAJMAADkAL9wv01BMzNDQtF8wZgADjGUjAVgAfEWlIwFZHR5cGWUk5SMAmY0lImIh5RSlChLA4wBPJROTk5K/////wUA8AVLAHSUYksESxOGlIwBQ5R0lFKULgAAAAA=”, “actions”: [2, 0, 2, 0], “action_prob”: [0.8999999761581421, 0.8999999761581421, 0.8999999761581421, 0.8999999761581421], “action_logp”: [-0.10536051541566849, -0.10536051541566849, -0.10536051541566849, -0.10536051541566849], “rewards”: [245.25428771972656, 766.2658081054688, -415.1706237792969, 1017.0550537109375], “prev_actions”: [0, 2, 0, 2], “prev_rewards”: [0.0, 245.25428771972656, 766.2658081054688, -415.1706237792969], “new_obs”: “BCJNGGhAsAEAAAAAAACnEAEAAGGABZWlAQABAPMZjBJudW1weS5jb3JlLm51bWVyaWOUjAtfZnJvbWJ1ZmZlcpSTlCiWMC8AgAAAgEIAAMhCCgAGAgDwD8A/0GROP83MF0NK0FFBAAA+QswV5UA8pXtB86q/QCgA8AlDHMFD58jjQL72lUDcArg/kAswPwAAYEEcAApQAA9MACUAAgAEmAAECAACTAD/ADMzF0Nwv01BMzNDQtF8wZgAEGD4QgAADEJSAAYCAAJMAP8AAAAVQ3OmRUFmZkBCFJvPTAAOMZSMBWAB8RaUjAVkdHlwZZSTlIwCZjSUiYiHlFKUKEsDjAE8lE5OTkr/////BQDwBUsAdJRiSwRLE4aUjAFDlHSUUpQuAAAAAA==”, “dones”: [false, false, false, true], “unroll_id”: [0, 0, 0, 0]}
{“type”: “SampleBatch”, “t”: [0, 1, 2, 3], “eps_id”: [1, 1, 1, 1], “agent_index”: [0, 0, 0, 0], “obs”: “BCJNGGhAsAEAAAAAAACnGQEAAGGABZWlAQABAPMZjBJudW1weS5jb3JlLm51bWVyaWOUjAtfZnJvbWJ1ZmZlcpSTlCiWMC8AQAAApkIGAAgCAPARzczMP7ygaj8AAOJCHtUuQc3MYkJSEhFBveB8QUZWSkAsAPANpMqiQx97t0CyViBAYNeXP5Yv4D4AABRCAAAFQyAABAIA/wiamdk/ZmZmP5qZ5UKor0dBZmZeQkrVGUwAEAQCAAZQAAxMAG8zM11C5s5MABFZhEIAALboAARMAP8AzczfQrMAY0GamV1C19QYmAAOMZSMBWAB8RaUjAVkdHlwZZSTlIwCZjSUiYiHlFKUKEsDjAE8lE5OTkr/////BQDwBUsAdJRiSwRLE4aUjAFDlHSUUpQuAAAAAA==”, “actions”: [3, 0, 2, 0], “action_prob”: [0.8999999761581421, 0.8999999761581421, 0.8999999761581421, 0.8999999761581421], “action_logp”: [-0.10536051541566849, -0.10536051541566849, -0.10536051541566849, -0.10536051541566849], “rewards”: [314.95916748046875, 487.30584716796875, 589.9122314453125, 1009.1389770507812], “prev_actions”: [0, 3, 0, 2], “prev_rewards”: [0.0, 314.95916748046875, 487.30584716796875, 589.9122314453125], “new_obs”: “BCJNGGhAsAEAAAAAAACnDAEAAGGABZWlAQABAPMZjBJudW1weS5jb3JlLm51bWVyaWOUjAtfZnJvbWJ1ZmZlcpSTlCiWMC8AgAAAFEIAAAVDCgAEAgDwEZqZ2T9mZmY/mpnlQqivR0FmZl5CStUZQb3gfEFGVkpAKADwBaTKokMfe7dAslYgQGDXlz+WL+A+GAACAgAGUAAMTABvMzNdQubOTAARYoRCAAC2QlAAAgIABEwA/wDNzN9CswBjQZqZXULX1BiYABEBtAAIUAAOTABfYUJQ8B1MAA4xlIwFYAHxFpSMBWR0eXBllJOUjAJmNJSJiIeUUpQoSwOMATyUTk5OSv////8FAPAFSwB0lGJLBEsThpSMAUOUdJRSlC4AAAAA”, “dones”: [false, false, false, true], “unroll_id”: [1, 1, 1, 1]}
{“type”: “SampleBatch”, “t”: [0, 1, 2, 3], “eps_id”: [2, 2, 2, 2], “agent_index”: [0, 0, 0, 0], “obs”: “BCJNGGhAsAEAAAAAAACnEwEAAGGABZWlAQABAPMZjBJudW1weS5jb3JlLm51bWVyaWOUjAtfZnJvbWJ1ZmZlcpSTlCiWMC8AQAAArkIGAAgCAPARzczMP7ygaj/NzO1CGgKcQWZmFkJGfrhA0XGsQAOz+z8sAPkMUWqzQ0RC40BC3XFA7TGaP2G2Aj8AAChCAADIUAD/CJqZ2T9mZmY/ZmbyQoXJo0GamRdCztTBTAAQIDBBaAAIUAAPTAAnWYxCAABImAD/CGZm5j/2LF8/zcz1Qoc9lkHNzBpCwUG8mAAOMZSMBWAB8RaUjAVkdHlwZZSTlIwCZjSUiYiHlFKUKEsDjAE8lE5OTkr/////BQDwBUsAdJRiSwRLE4aUjAFDlHSUUpQuAAAAAA==”, “actions”: [2, 0, 1, 0], “action_prob”: [0.8999999761581421, 0.8999999761581421, 0.8999999761581421, 0.8999999761581421], “action_logp”: [-0.10536051541566849, -0.10536051541566849, -0.10536051541566849, -0.10536051541566849], “rewards”: [-166.92562866210938, 153.8045654296875, -222.21136474609375, 205.7904510498047], “prev_actions”: [0, 2, 0, 1], “prev_rewards”: [0.0, -166.92562866210938, 153.8045654296875, -222.21136474609375], “new_obs”: “BCJNGGhAsAEAAAAAAACnCAEAAGGABZWlAQABAPMZjBJudW1weS5jb3JlLm51bWVyaWOUjAtfZnJvbWJ1ZmZlcpSTlCiWMC8AgAAAKEIAAMhCCgAEAgDwEZqZ2T9mZmY/ZmbyQoXJo0GamRdCztTBQNFxrEADs/s/KADwCVFqs0NEQuNAQt1xQO0xmj9htgI/AAAwQRwACFAAD0wAJ1mMQgAASJgA/whmZuY/9ixfP83M9UKHPZZBzcwaQsFBvJgAEBPQmAAGUAAMTAB/mpkZQkeNsEwADjGUjAVgAfEWlIwFZHR5cGWUk5SMAmY0lImIh5RSlChLA4wBPJROTk5K/////wUA8AVLAHSUYksESxOGlIwBQ5R0lFKULgAAAAA=”, “dones”: [false, false, false, true], “unroll_id”: [2, 2, 2, 2]}
{“type”: “SampleBatch”, “t”: [0, 1, 2, 3], “eps_id”: [3, 3, 3, 3], “agent_index”: [0, 0, 0, 0], “obs”: “BCJNGGhAsAEAAAAAAACnGQEAAGGABZWlAQABAPMZjBJudW1weS5jb3JlLm51bWVyaWOUjAtfZnJvbWJ1ZmZlcpSTlCiWMC8AQAAA3EIGAAgCAPARmpnZP0HxRz8zMwxD6N7PQQAAREIlxpZAmvR5QTKcj0AsAPkMfNq8Q45vF0G3u+VALhOQP9bGxD4AAHxCAADIUAD/CGZm5j+nkj8/ZmYPQybawkEAAEJCjDSUTAAQIJBBaAAIUAAMTAB/zcw+QuUkj0wAEB2KmAD/CDMz8z8zMzM/MzMJQ9R1yUHNzEBCN9yJTAAOMZSMBWAB8RaUjAVkdHlwZZSTlIwCZjSUiYiHlFKUKEsDjAE8lE5OTkr/////BQDwBUsAdJRiSwRLE4aUjAFDlHSUUpQuAAAAAA==”, “actions”: [2, 0, 2, 0], “action_prob”: [0.8999999761581421, 0.8999999761581421, 0.8999999761581421, 0.8999999761581421], “action_logp”: [-0.10536051541566849, -0.10536051541566849, -0.10536051541566849, -0.10536051541566849], “rewards”: [285.62542724609375, 682.7392578125, 310.1163635253906, 642.4901123046875], “prev_actions”: [0, 2, 0, 2], “prev_rewards”: [0.0, 285.62542724609375, 682.7392578125, 310.1163635253906], “new_obs”: “BCJNGGhAsAEAAAAAAACnCwEAAGGABZWlAQABAPMZjBJudW1weS5jb3JlLm51bWVyaWOUjAtfZnJvbWJ1ZmZlcpSTlCiWMC8AgAAAfEIAAMhCCgAEAgDwEWZm5j+nkj8/ZmYPQybawkEAAEJCjDSUQJr0eUEynI9AKADwCXzavEOObxdBt7vlQC4TkD/WxsQ+AACQQRwACFAADEwAf83MPkLlJI9MABAdipgA/wgzM/M/MzMzPzMzCUPUdclBzcxAQjfciUwAEB3QmAAMTAB/ZmZAQp5FjUwADjGUjAVgAfEWlIwFZHR5cGWUk5SMAmY0lImIh5RSlChLA4wBPJROTk5K/////wUA8AVLAHSUYksESxOGlIwBQ5R0lFKULgAAAAA=”, “dones”: [false, false, false, true], “unroll_id”: [3, 3, 3, 3]}
{“type”: “SampleBatch”, “t”: [0, 1, 2, 3], “eps_id”: [4, 4, 4, 4], “agent_index”: [0, 0, 0, 0], “obs”: “BCJNGGhAsAEAAAAAAACnGQEAAGGABZWlAQABAPMZjBJudW1weS5jb3JlLm51bWVyaWOUjAtfZnJvbWJ1ZmZlcpSTlCiWMC8AQAAAQUMGAAgCAPARmpkZQO+Igj8zM/hCK8WAQc3MMkLJGZ5A81VTQUDfz0AsAPANHVrWQ3zRB0E/IoRAkPb8P4ZoGD8AABBDAABIQiAABAIABEwA/wBmZv5C5SSPQZqZMUItFZJMABATwkgABlAADEwAfzMzNULMaoJMABBT0EIAAMhQAAICAARMAP8AzcwAQ5qZeUHNzDRCuciDTAAOMZSMBWAB8RaUjAVkdHlwZZSTlIwCZjSUiYiHlFKUKEsDjAE8lE5OTkr/////BQDwBUsAdJRiSwRLE4aUjAFDlHSUUpQuAAAAAA==”, “actions”: [1, 0, 2, 0], “action_prob”: [0.8999999761581421, 0.8999999761581421, 0.8999999761581421, 0.8999999761581421], “action_logp”: [-0.10536051541566849, -0.10536051541566849, -0.10536051541566849, -0.10536051541566849], “rewards”: [-66.07181549072266, 429.1001281738281, -66.27174377441406, 568.89013671875], “prev_actions”: [0, 1, 0, 2], “prev_rewards”: [0.0, -66.07181549072266, 429.1001281738281, -66.27174377441406], “new_obs”: “BCJNGGhAsAEAAAAAAACnDwEAAGGABZWlAQABAPMZjBJudW1weS5jb3JlLm51bWVyaWOUjAtfZnJvbWJ1ZmZlcpSTlCiWMC8AgAAAEEMAAEhCCgAEAgDwEZqZGUDviII/Zmb+QuUkj0GamTFCLRWSQPNVU0FA389AKADzCB1a1kN80QdBPyKEQJD2/D+GaBg/AADCSAAGUAAMTAB/MzM1QsxqgkwAEFPQQgAAyFAAAgIABEwA/wDNzABDmpl5Qc3MNEK5yINMABATVEgABlAADEwAfwAAOkIUt2pMAA4xlIwFYAHxFpSMBWR0eXBllJOUjAJmNJSJiIeUUpQoSwOMATyUTk5OSv////8FAPAFSwB0lGJLBEsThpSMAUOUdJRSlC4AAAAA”, “dones”: [false, false, false, true], “unroll_id”: [4, 4, 4, 4]}
{“type”: “SampleBatch”, “t”: [0, 1, 2, 3], “eps_id”: [5, 5, 5, 5], “agent_index”: [0, 0, 0, 0], “obs”: “BCJNGGhAsAEAAAAAAACnGAEAAGGABZWlAQABAPMZjBJudW1weS5jb3JlLm51bWVyaWOUjAtfZnJvbWJ1ZmZlcpSTlCiWMC8AQAAAMEIGAAsCAPAOQAAAgD9mZhJDCwOFQc3MKEL/uuFA5XyQQbFul0AsAPwMjdPvQ1Ml7kAyiJlARQniP4V+Nj8AABBBAADcUAABTAD/ADMzC0OD13JBzcwqQo/nyUwAEByOSAAAAgAJTAB/AAAuQhOGzUwAEGD4QQAAB0NBAAQCAP8IZmYGQIqCcT+amQlDefRqQQAAKkINTsNMAA4xlIwFYAHxFpSMBWR0eXBllJOUjAJmNJSJiIeUUpQoSwOMATyUTk5OSv////8FAPAFSwB0lGJLBEsThpSMAUOUdJRSlC4AAAAA”, “actions”: [3, 0, 3, 0], “action_prob”: [0.8999999761581421, 0.8999999761581421, 0.029999999329447746, 0.8999999761581421], “action_logp”: [-0.10536051541566849, -0.10536051541566849, -3.5065579414367676, -0.10536051541566849], “rewards”: [-55.326446533203125, 741.5477905273438, 116.07538604736328, 530.122314453125], “prev_actions”: [0, 3, 0, 3], “prev_rewards”: [0.0, -55.326446533203125, 741.5477905273438, 116.07538604736328], “new_obs”: “BCJNGGhAsAEAAAAAAACnEQEAAGGABZWlAQABAPMZjBJudW1weS5jb3JlLm51bWVyaWOUjAtfZnJvbWJ1ZmZlcpSTlCiWMC8AgAAAEEEAANxCCgAHAgDwDkAAAIA/MzMLQ4PXckHNzCpCj+fJQOV8kEGxbpdAKAD8CI3T70NTJe5AMoiZQEUJ4j+FfjY/AACOSAAAAgAJTAB/AAAuQhOGzUwAEGD4QQAAB0NBAAQCAP8IZmYGQIqCcT+amQlDefRqQQAAKkINTsNMABAEAgAGUAAMTAB/ZmYoQukezkwADjGUjAVgAfEWlIwFZHR5cGWUk5SMAmY0lImIh5RSlChLA4wBPJROTk5K/////wUA8AVLAHSUYksESxOGlIwBQ5R0lFKULgAAAAA=”, “dones”: [false, false, false, true], “unroll_id”: [5, 5, 5, 5]}
{“type”: “SampleBatch”, “t”: [0, 1, 2, 3], “eps_id”: [6, 6, 6, 6], “agent_index”: [0, 0, 0, 0], “obs”: “BCJNGGhAsAEAAAAAAACnHwEAAGGABZWlAQABAPMZjBJudW1weS5jb3JlLm51bWVyaWOUjAtfZnJvbWJ1ZmZlcpSTlCiWMC8AQAAAM0MGAAgCAPARZmamP7yg6j5mZulCQjdtQQAAekLuwgRB16wfQUmMjkAsAPANSzaCQ545sUCGJWJADtHDPzRLFj8AAPpCAABIQiAABAIA/wiamZk/zczMPjMz6EK8hmtBmpl3Qq2lCkwAEBncSAAAAgAMTAB/zcx4QrRyC0wAEFlAQgAAyFAAAOQA/wSE6yM/ZmbyQrdsh0EAAHZCCK0GTAAOMZSMBWAB8RaUjAVkdHlwZZSTlIwCZjSUiYiHlFKUKEsDjAE8lE5OTkr/////BQDwBUsAdJRiSwRLE4aUjAFDlHSUUpQuAAAAAA==”, “actions”: [1, 0, 2, 0], “action_prob”: [0.8999999761581421, 0.8999999761581421, 0.8999999761581421, 0.8999999761581421], “action_logp”: [-0.10536051541566849, -0.10536051541566849, -0.10536051541566849, -0.10536051541566849], “rewards”: [87.2523193359375, 480.400390625, 284.8858337402344, 384.8746337890625], “prev_actions”: [0, 1, 0, 2], “prev_rewards”: [0.0, 87.2523193359375, 480.400390625, 284.8858337402344], “new_obs”: “BCJNGGhAsAEAAAAAAACnDwEAAGGABZWlAQABAPMZjBJudW1weS5jb3JlLm51bWVyaWOUjAtfZnJvbWJ1ZmZlcpSTlCiWMC8AgAAA+kIAAEhCCgAEAgDwEZqZmT/NzMw+MzPoQryGa0GamXdCraUKQdesH0FJjI5AKAD5CEs2gkOeObFAhiViQA7Rwz80SxY/AADcSAAAAgAMTAB/zcx4QrRyC0wAEFlAQgAAyFAA/whmZqY/hOsjP2Zm8kK3bIdBAAB2QgitBkwAEAQCAAZQAA5MAG9+QlqGzEDkAA0xlIwFYAHxFpSMBWR0eXBllJOUjAJmNJSJiIeUUpQoSwOMATyUTk5OSv////8FAPAFSwB0lGJLBEsThpSMAUOUdJRSlC4AAAAA”, “dones”: [false, false, false, true], “unroll_id”: [6, 6, 6, 6]}
{“type”: “SampleBatch”, “t”: [0, 1, 2, 3], “eps_id”: [7, 7, 7, 7], “agent_index”: [0, 0, 0, 0], “obs”: “BCJNGGhAsAEAAAAAAACnHAEAAGGABZWlAQABAPMZjBJudW1weS5jb3JlLm51bWVyaWOUjAtfZnJvbWJ1ZmZlcpSTlCiWMC8AQAAAcEEGAAgCAPARmpk5QEqmVD/NzPVC8KjVQWZmSkJqedtAG5eFQSEnsUAsAPAF427XQzo9HkGfwsJAtyTAP76l8T4YAEAAAJhCBgAEAgD/CDMzM0D2LF8/AADrQpHf70HNzEpCZkPdTAAUKCBCUAAETABxmpnvQkM7y5gAP/Ys30wAFCIJQ1AAAgIABEwA783M7EKj8L9BMzNRQreQTAAPMZSMBWAB8RaUjAVkdHlwZZSTlIwCZjSUiYiHlFKUKEsDjAE8lE5OTkr/////BQDwBUsAdJRiSwRLE4aUjAFDlHSUUpQuAAAAAA==”, “actions”: [5, 0, 4, 0], “action_prob”: [0.8999999761581421, 0.8999999761581421, 0.8999999761581421, 0.8999999761581421], “action_logp”: [-0.10536051541566849, -0.10536051541566849, -0.10536051541566849, -0.10536051541566849], “rewards”: [-1634.9912109375, -850.5354614257812, -760.9075317382812, -1226.353515625], “prev_actions”: [0, 5, 0, 4], “prev_rewards”: [0.0, -1634.9912109375, -850.5354614257812, -760.9075317382812], “new_obs”: “BCJNGGhAsAEAAAAAAACnHQEAAGGABZWlAQABAPMZjBJudW1weS5jb3JlLm51bWVyaWOUjAtfZnJvbWJ1ZmZlcpSTlCiWMC8AAgIAIphCCAACAgDwETMzM0D2LF8/AADrQpHf70HNzEpCZkPdQBuXhUEhJ7FAJgDwBeNu10M6PR5Bn8LCQLckwD++pfE+GABIAAAgQlAABEwA/wCame9CQzvLQWZmSkL2LN9MABQiCUNQAAICAARMAO/NzOxCo/C/QTMzUUK3kEwAFSiMQlAA/whmZiZA74iCP5qZ6EJ5TsNBmplNQiI6wpgADjGUjAVgAfEWlIwFZHR5cGWUk5SMAmY0lImIh5RSlChLA4wBPJROTk5K/////wUA8AVLAHSUYksESxOGlIwBQ5R0lFKULgAAAAA=”, “dones”: [false, false, false, true], “unroll_id”: [7, 7, 7, 7]}

Do you know why that error occurs?

Thanks,
Stefan

Hi @steff, thanks for providing details like test data for the question! I have a couple of questions: which version of Ray do you use? And how many files are you reading?

Hi @jianxiao. I’m using Ray 2.0 and I’ve tried it with different offline data sets. One such offline data set contained only one file, and the other contained multiple files. This error occurred with both.

Hi @jianxiao. Found the problem. The offline data files were named with extension .txt instead of .json. Changed that and now it works fine. Thanks for your help.

1 Like