Test basic device processor functionality on CPU.
()
| 25 | |
| 26 | |
| 27 | def test_basic_functionality(): |
| 28 | """Test basic device processor functionality on CPU.""" |
| 29 | processor = DeviceProcessorStep(device="cpu") |
| 30 | |
| 31 | # Create a transition with CPU tensors |
| 32 | observation = {OBS_STATE: torch.randn(10), OBS_IMAGE: torch.randn(3, 224, 224)} |
| 33 | action = torch.randn(5) |
| 34 | reward = torch.tensor(1.0) |
| 35 | done = torch.tensor(False) |
| 36 | truncated = torch.tensor(False) |
| 37 | |
| 38 | transition = create_transition( |
| 39 | observation=observation, action=action, reward=reward, done=done, truncated=truncated |
| 40 | ) |
| 41 | |
| 42 | result = processor(transition) |
| 43 | |
| 44 | # Check that all tensors are on CPU |
| 45 | assert result[TransitionKey.OBSERVATION][OBS_STATE].device.type == "cpu" |
| 46 | assert result[TransitionKey.OBSERVATION][OBS_IMAGE].device.type == "cpu" |
| 47 | assert result[TransitionKey.ACTION].device.type == "cpu" |
| 48 | assert result[TransitionKey.REWARD].device.type == "cpu" |
| 49 | assert result[TransitionKey.DONE].device.type == "cpu" |
| 50 | assert result[TransitionKey.TRUNCATED].device.type == "cpu" |
| 51 | |
| 52 | |
| 53 | @pytest.mark.skipif(not torch.cuda.is_available(), reason="CUDA not available") |
nothing calls this directly
no test coverage detected