We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
[tensor] fix some unittests

[tensor] fix some unittests

[tensor] fix some unittests


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `colossalai/accelerator/npu_accelerator.py`
Content:
```
1 #!/usr/bin/env python
2 
3 from typing import Any, Callable, Dict, List, Optional, Tuple, Union
4 
5 import torch
6 import torch.distributed as dist
7 
8 from .base_accelerator import BaseAccelerator
9 
10 try:
11     import torch_npu  # noqa
12 except ImportError:
13     pass
14 
15 
16 __all__ = ["NpuAccelerator"]
17 
18 
19 class NpuAccelerator(BaseAccelerator):
20     """
21     Accelerator class for Huawei NPU devices.
22     """
23 
24     def __init__(self):
25         super().__init__(name="npu", communication_backend="hccl", is_synchronous=False)
26 
27     # =======================
28     # device APIs
29     # =======================
30     def get_version(self) -> str:
31         """
32         Return the version of the accelerator which torch is built against.
33         """
34         return torch.version.npu
35 
36     def get_current_device(self) -> torch.device:
37         """
38         Return the current device.
39         """
40         return torch.device(f"npu:{torch.npu.current_device()}")
41 
42     def current_device(self) -> int:
43         """
44         Return the current device index.
45         """
46         return torch.npu.current_device()
47 
48     def set_device(self, device: Optional[Union[torch.device, int]] = None) -> None:
49         """
50         Bind the current process to a device.
51         """
52         if device is None:
53             if not dist.is_initialized():
54                 raise RuntimeError("Cannot get current device when distributed is not initialized.")
55             device = dist.get_rank() % self.device_count()
56         torch.npu.set_device(device)
57 
58     def get_device_name(self, device: Union[torch.device, int]) -> str:
59         """
60         Return the name of the device.
61         """
62         return torch.npu.get_device_name(device)
63 
64     def synchronize(self, device: Union[torch.device, int] = None):
65         """
66         Synchronize the current process.
67         """
68         torch.npu.synchronize(device)
69 
70     def is_available(self):
71         """
72         Check if the accelerator is available.
73         """
74         return torch.npu.is_available()
75 
76     def device_count(self):
77         """
78         Return the number of devices on the machine.
79         """
80         return torch.npu.device_count()
81 
82     def get_device_capability(self, device=None) -> Tuple[int, int]:
83         """
84         Gets the npu capability of a device.
85         """
86         return torch.npu.get_device_capability(device)
87 
88     def get_device_name(self, device=None) -> str:
89         """
90         Gets the name of a device.
91         """
92         return torch.npu.get_device_name(device)
93 
94     def get_device_properties(self, device):
95         """
96         Gets the properties of a device.
97         """
98         return torch.npu.get_device_properties(device)
99 
100     def utilization(self, device=None) -> int:
101         """
102         Returns the percent of time over the past sample period during which one or more kernels was executing on the GPU as given by nvidia-smi
103         """
104         return torch.npu.utilization(device)
105 
106     # =======================
107     # random number generator APIs
108     # =======================
109     def get_rng_state(self, device="npu") -> torch.Tensor:
110         """
111         Returns the random number generator state of the specified GPU as a ByteTensor.
112         """
113         return torch.npu.get_rng_state(device)
114 
115     def get_rng_state_all(self) -> List[torch.Tensor]:
116         """
117         Returns a list of ByteTensor representing the random number states of all devices.
118         """
119         return torch.npu.get_rng_state_all()
120 
121     def set_rng_state(self, new_state: torch.ByteTensor, device: str = "npu") -> None:
122         """
123         Sets the random number generator state of the specified GPU.
124         """
125         torch.npu.set_rng_state(new_state, device)
126 
127     def set_rng_state_all(self, new_states: List[torch.ByteTensor]) -> None:
128         """
129         Sets the random number generator state of all devices.
130         """
131         torch.npu.set_rng_state_all(new_states)
132 
133     def manual_seed(self, seed: int) -> None:
134         """
135         Sets the seed for generating random numbers for the current GPU.
136         """
137         torch.npu.manual_seed(seed)
138 
139     def manual_seed_all(self, seed: int) -> None:
140         """
141         Set the random seed for the all processes.
142         """
143         torch.npu.manual_seed_all(seed)
144 
145     def seed(self) -> None:
146         """
147         Sets the seed for generating random numbers to a random number for the current GPU.
148         """
149         torch.npu.seed()
150 
151     def seed_all(self) -> None:
152         """
153         Sets the seed for generating random numbers to a random number on all GPUs.
154         """
155         torch.npu.seed_all()
156 
157     def initial_seed(self) -> int:
158         """
159         Returns the current random seed of the current GPU.
160         """
161         return torch.npu.initial_seed()
162 
163     # =======================
164     # memory management APIs
165     # =======================
166 
167     def empty_cache(self) -> None:
168         """
169         Releases all unoccupied cached memory currently held by the caching allocator so that those can be used in other GPU application and visible in nvidia-smi.
170         """
171         torch.npu.empty_cache()
172 
173     def memory_stats(self, device=None) -> Dict[str, Any]:
174         """
175         Returns a dictionary of npu memory allocator statistics for a given device.
176         """
177         return torch.npu.memory_stats(device=device)
178 
179     def memory_summary(self, device=None, abbreviated=False) -> str:
180         """
181         Returns a human-readable printout of the current memory allocator statistics for a given device.
182         """
183         return torch.npu.memory_summary(device=device, abbreviated=abbreviated)
184 
185     def memory_snapshot(self):
186         """
187         Returns a snapshot of the npu memory allocator state across all devices.
188         """
189         return torch.npu.memory_snapshot()
190 
191     def memory_allocated(self, device=None) -> int:
192         """
193         Returns the current GPU memory occupied by tensors in bytes for a given device.
194         """
195         return torch.npu.memory_allocated(device=device)
196 
197     def max_memory_allocated(self, device=None) -> int:
198         """
199         Returns the maximum GPU memory occupied by tensors in bytes for a given device.
200         """
201         return torch.npu.max_memory_allocated(device=device)
202 
203     def reset_max_memory_allocated(self, device=None) -> None:
204         """
205         Resets the starting point in tracking maximum GPU memory occupied by tensors for a given device.
206         """
207         torch.npu.reset_max_memory_allocated(device=device)
208 
209     def reset_max_memory_cached(self, device=None) -> None:
210         """
211         Resets the starting point in tracking maximum GPU memory managed by the caching allocator for a given device.
212         """
213         torch.npu.reset_max_memory_cached(device=device)
214 
215     def memory_reserved(self, device=None) -> int:
216         """
217         Returns the current GPU memory managed by the caching allocator in bytes for a given device.
218         """
219         return torch.npu.memory_reserved(device=device)
220 
221     def max_memory_reserved(self, device=None) -> int:
222         """
223         Returns the maximum GPU memory managed by the caching allocator in bytes for a given device.
224         """
225         return torch.npu.max_memory_reserved(device=device)
226 
227     def set_per_process_memory_fraction(self, fraction: float, device=None) -> None:
228         """
229         Set memory fraction for a process.
230         """
231         torch.npu.set_per_process_memory_fraction(fraction, device=device)
232 
233     def reset_peak_memory_stats(self, device=None) -> None:
234         """
235         Resets the "peak" stats tracked by the npu memory allocator.
236         """
237         torch.npu.reset_peak_memory_stats(device=device)
238 
239     # =======================
240     # streams and events APIs
241     # =======================
242 
243     def Stream(self, device=None, priority=0, **kwargs):
244         """
245         A npu stream is a linear sequence of execution that belongs to a specific device, independent from other streams. See npu-semantics for details.
246         """
247         return torch.npu.Stream(device, priority, **kwargs)
248 
249     def Event(self, enable_timing: bool = False, blocking: bool = False, interprocess: bool = False):
250         """
251         npu events are synchronization markers that can be used to monitor the device's progress, to accurately measure timing, and to synchronize npu streams.
252         """
253         return torch.npu.Event(enable_timing, blocking, interprocess)
254 
255     def current_stream(self, device=None):
256         """
257         Returns the currently selected Stream for a given device.
258         """
259         return torch.npu.current_stream(device)
260 
261     def default_stream(self, device=None):
262         """
263         Returns the default Stream for a given device.
264         """
265         return torch.npu.default_stream(device)
266 
267     def set_stream(self, stream_):
268         """
269         Sets the current stream.This is a wrapper API to set the stream.
270         """
271         torch.npu.set_stream(stream_)
272 
273     def stream(self, stream_):
274         """
275         Wrapper around the Context-manager StreamContext that selects a given stream.
276         """
277         return torch.npu.stream(stream_)
278 
279     # =======================
280     # amp APIs
281     # =======================
282     def autocast(
283         self, enabled: bool = True, dtype: torch.dtype = torch.float16, cache_enabled: bool = True
284     ) -> Callable:
285         """
286         Return autocast function
287         """
288         return torch.npu.amp.autocast(enabled=enabled, dtype=dtype, cache_enabled=cache_enabled)
289
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/colossalai/accelerator/npu_accelerator.py b/colossalai/accelerator/npu_accelerator.py
--- a/colossalai/accelerator/npu_accelerator.py
+++ b/colossalai/accelerator/npu_accelerator.py
@@ -31,7 +31,7 @@
         """
         Return the version of the accelerator which torch is built against.
         """
-        return torch.version.npu
+        return torch.version.cann
 
     def get_current_device(self) -> torch.device:
         """

{"golden_diff": "diff --git a/colossalai/accelerator/npu_accelerator.py b/colossalai/accelerator/npu_accelerator.py\n--- a/colossalai/accelerator/npu_accelerator.py\n+++ b/colossalai/accelerator/npu_accelerator.py\n@@ -31,7 +31,7 @@\n         \"\"\"\n         Return the version of the accelerator which torch is built against.\n         \"\"\"\n-        return torch.version.npu\n+        return torch.version.cann\n \n     def get_current_device(self) -> torch.device:\n         \"\"\"\n", "issue": "[tensor] fix some unittests\n\n[tensor] fix some unittests\n\n[tensor] fix some unittests\n\n", "before_files": [{"content": "#!/usr/bin/env python\n\nfrom typing import Any, Callable, Dict, List, Optional, Tuple, Union\n\nimport torch\nimport torch.distributed as dist\n\nfrom .base_accelerator import BaseAccelerator\n\ntry:\n    import torch_npu  # noqa\nexcept ImportError:\n    pass\n\n\n__all__ = [\"NpuAccelerator\"]\n\n\nclass NpuAccelerator(BaseAccelerator):\n    \"\"\"\n    Accelerator class for Huawei NPU devices.\n    \"\"\"\n\n    def __init__(self):\n        super().__init__(name=\"npu\", communication_backend=\"hccl\", is_synchronous=False)\n\n    # =======================\n    # device APIs\n    # =======================\n    def get_version(self) -> str:\n        \"\"\"\n        Return the version of the accelerator which torch is built against.\n        \"\"\"\n        return torch.version.npu\n\n    def get_current_device(self) -> torch.device:\n        \"\"\"\n        Return the current device.\n        \"\"\"\n        return torch.device(f\"npu:{torch.npu.current_device()}\")\n\n    def current_device(self) -> int:\n        \"\"\"\n        Return the current device index.\n        \"\"\"\n        return torch.npu.current_device()\n\n    def set_device(self, device: Optional[Union[torch.device, int]] = None) -> None:\n        \"\"\"\n        Bind the current process to a device.\n        \"\"\"\n        if device is None:\n            if not dist.is_initialized():\n                raise RuntimeError(\"Cannot get current device when distributed is not initialized.\")\n            device = dist.get_rank() % self.device_count()\n        torch.npu.set_device(device)\n\n    def get_device_name(self, device: Union[torch.device, int]) -> str:\n        \"\"\"\n        Return the name of the device.\n        \"\"\"\n        return torch.npu.get_device_name(device)\n\n    def synchronize(self, device: Union[torch.device, int] = None):\n        \"\"\"\n        Synchronize the current process.\n        \"\"\"\n        torch.npu.synchronize(device)\n\n    def is_available(self):\n        \"\"\"\n        Check if the accelerator is available.\n        \"\"\"\n        return torch.npu.is_available()\n\n    def device_count(self):\n        \"\"\"\n        Return the number of devices on the machine.\n        \"\"\"\n        return torch.npu.device_count()\n\n    def get_device_capability(self, device=None) -> Tuple[int, int]:\n        \"\"\"\n        Gets the npu capability of a device.\n        \"\"\"\n        return torch.npu.get_device_capability(device)\n\n    def get_device_name(self, device=None) -> str:\n        \"\"\"\n        Gets the name of a device.\n        \"\"\"\n        return torch.npu.get_device_name(device)\n\n    def get_device_properties(self, device):\n        \"\"\"\n        Gets the properties of a device.\n        \"\"\"\n        return torch.npu.get_device_properties(device)\n\n    def utilization(self, device=None) -> int:\n        \"\"\"\n        Returns the percent of time over the past sample period during which one or more kernels was executing on the GPU as given by nvidia-smi\n        \"\"\"\n        return torch.npu.utilization(device)\n\n    # =======================\n    # random number generator APIs\n    # =======================\n    def get_rng_state(self, device=\"npu\") -> torch.Tensor:\n        \"\"\"\n        Returns the random number generator state of the specified GPU as a ByteTensor.\n        \"\"\"\n        return torch.npu.get_rng_state(device)\n\n    def get_rng_state_all(self) -> List[torch.Tensor]:\n        \"\"\"\n        Returns a list of ByteTensor representing the random number states of all devices.\n        \"\"\"\n        return torch.npu.get_rng_state_all()\n\n    def set_rng_state(self, new_state: torch.ByteTensor, device: str = \"npu\") -> None:\n        \"\"\"\n        Sets the random number generator state of the specified GPU.\n        \"\"\"\n        torch.npu.set_rng_state(new_state, device)\n\n    def set_rng_state_all(self, new_states: List[torch.ByteTensor]) -> None:\n        \"\"\"\n        Sets the random number generator state of all devices.\n        \"\"\"\n        torch.npu.set_rng_state_all(new_states)\n\n    def manual_seed(self, seed: int) -> None:\n        \"\"\"\n        Sets the seed for generating random numbers for the current GPU.\n        \"\"\"\n        torch.npu.manual_seed(seed)\n\n    def manual_seed_all(self, seed: int) -> None:\n        \"\"\"\n        Set the random seed for the all processes.\n        \"\"\"\n        torch.npu.manual_seed_all(seed)\n\n    def seed(self) -> None:\n        \"\"\"\n        Sets the seed for generating random numbers to a random number for the current GPU.\n        \"\"\"\n        torch.npu.seed()\n\n    def seed_all(self) -> None:\n        \"\"\"\n        Sets the seed for generating random numbers to a random number on all GPUs.\n        \"\"\"\n        torch.npu.seed_all()\n\n    def initial_seed(self) -> int:\n        \"\"\"\n        Returns the current random seed of the current GPU.\n        \"\"\"\n        return torch.npu.initial_seed()\n\n    # =======================\n    # memory management APIs\n    # =======================\n\n    def empty_cache(self) -> None:\n        \"\"\"\n        Releases all unoccupied cached memory currently held by the caching allocator so that those can be used in other GPU application and visible in nvidia-smi.\n        \"\"\"\n        torch.npu.empty_cache()\n\n    def memory_stats(self, device=None) -> Dict[str, Any]:\n        \"\"\"\n        Returns a dictionary of npu memory allocator statistics for a given device.\n        \"\"\"\n        return torch.npu.memory_stats(device=device)\n\n    def memory_summary(self, device=None, abbreviated=False) -> str:\n        \"\"\"\n        Returns a human-readable printout of the current memory allocator statistics for a given device.\n        \"\"\"\n        return torch.npu.memory_summary(device=device, abbreviated=abbreviated)\n\n    def memory_snapshot(self):\n        \"\"\"\n        Returns a snapshot of the npu memory allocator state across all devices.\n        \"\"\"\n        return torch.npu.memory_snapshot()\n\n    def memory_allocated(self, device=None) -> int:\n        \"\"\"\n        Returns the current GPU memory occupied by tensors in bytes for a given device.\n        \"\"\"\n        return torch.npu.memory_allocated(device=device)\n\n    def max_memory_allocated(self, device=None) -> int:\n        \"\"\"\n        Returns the maximum GPU memory occupied by tensors in bytes for a given device.\n        \"\"\"\n        return torch.npu.max_memory_allocated(device=device)\n\n    def reset_max_memory_allocated(self, device=None) -> None:\n        \"\"\"\n        Resets the starting point in tracking maximum GPU memory occupied by tensors for a given device.\n        \"\"\"\n        torch.npu.reset_max_memory_allocated(device=device)\n\n    def reset_max_memory_cached(self, device=None) -> None:\n        \"\"\"\n        Resets the starting point in tracking maximum GPU memory managed by the caching allocator for a given device.\n        \"\"\"\n        torch.npu.reset_max_memory_cached(device=device)\n\n    def memory_reserved(self, device=None) -> int:\n        \"\"\"\n        Returns the current GPU memory managed by the caching allocator in bytes for a given device.\n        \"\"\"\n        return torch.npu.memory_reserved(device=device)\n\n    def max_memory_reserved(self, device=None) -> int:\n        \"\"\"\n        Returns the maximum GPU memory managed by the caching allocator in bytes for a given device.\n        \"\"\"\n        return torch.npu.max_memory_reserved(device=device)\n\n    def set_per_process_memory_fraction(self, fraction: float, device=None) -> None:\n        \"\"\"\n        Set memory fraction for a process.\n        \"\"\"\n        torch.npu.set_per_process_memory_fraction(fraction, device=device)\n\n    def reset_peak_memory_stats(self, device=None) -> None:\n        \"\"\"\n        Resets the \"peak\" stats tracked by the npu memory allocator.\n        \"\"\"\n        torch.npu.reset_peak_memory_stats(device=device)\n\n    # =======================\n    # streams and events APIs\n    # =======================\n\n    def Stream(self, device=None, priority=0, **kwargs):\n        \"\"\"\n        A npu stream is a linear sequence of execution that belongs to a specific device, independent from other streams. See npu-semantics for details.\n        \"\"\"\n        return torch.npu.Stream(device, priority, **kwargs)\n\n    def Event(self, enable_timing: bool = False, blocking: bool = False, interprocess: bool = False):\n        \"\"\"\n        npu events are synchronization markers that can be used to monitor the device's progress, to accurately measure timing, and to synchronize npu streams.\n        \"\"\"\n        return torch.npu.Event(enable_timing, blocking, interprocess)\n\n    def current_stream(self, device=None):\n        \"\"\"\n        Returns the currently selected Stream for a given device.\n        \"\"\"\n        return torch.npu.current_stream(device)\n\n    def default_stream(self, device=None):\n        \"\"\"\n        Returns the default Stream for a given device.\n        \"\"\"\n        return torch.npu.default_stream(device)\n\n    def set_stream(self, stream_):\n        \"\"\"\n        Sets the current stream.This is a wrapper API to set the stream.\n        \"\"\"\n        torch.npu.set_stream(stream_)\n\n    def stream(self, stream_):\n        \"\"\"\n        Wrapper around the Context-manager StreamContext that selects a given stream.\n        \"\"\"\n        return torch.npu.stream(stream_)\n\n    # =======================\n    # amp APIs\n    # =======================\n    def autocast(\n        self, enabled: bool = True, dtype: torch.dtype = torch.float16, cache_enabled: bool = True\n    ) -> Callable:\n        \"\"\"\n        Return autocast function\n        \"\"\"\n        return torch.npu.amp.autocast(enabled=enabled, dtype=dtype, cache_enabled=cache_enabled)\n", "path": "colossalai/accelerator/npu_accelerator.py"}], "after_files": [{"content": "#!/usr/bin/env python\n\nfrom typing import Any, Callable, Dict, List, Optional, Tuple, Union\n\nimport torch\nimport torch.distributed as dist\n\nfrom .base_accelerator import BaseAccelerator\n\ntry:\n    import torch_npu  # noqa\nexcept ImportError:\n    pass\n\n\n__all__ = [\"NpuAccelerator\"]\n\n\nclass NpuAccelerator(BaseAccelerator):\n    \"\"\"\n    Accelerator class for Huawei NPU devices.\n    \"\"\"\n\n    def __init__(self):\n        super().__init__(name=\"npu\", communication_backend=\"hccl\", is_synchronous=False)\n\n    # =======================\n    # device APIs\n    # =======================\n    def get_version(self) -> str:\n        \"\"\"\n        Return the version of the accelerator which torch is built against.\n        \"\"\"\n        return torch.version.cann\n\n    def get_current_device(self) -> torch.device:\n        \"\"\"\n        Return the current device.\n        \"\"\"\n        return torch.device(f\"npu:{torch.npu.current_device()}\")\n\n    def current_device(self) -> int:\n        \"\"\"\n        Return the current device index.\n        \"\"\"\n        return torch.npu.current_device()\n\n    def set_device(self, device: Optional[Union[torch.device, int]] = None) -> None:\n        \"\"\"\n        Bind the current process to a device.\n        \"\"\"\n        if device is None:\n            if not dist.is_initialized():\n                raise RuntimeError(\"Cannot get current device when distributed is not initialized.\")\n            device = dist.get_rank() % self.device_count()\n        torch.npu.set_device(device)\n\n    def get_device_name(self, device: Union[torch.device, int]) -> str:\n        \"\"\"\n        Return the name of the device.\n        \"\"\"\n        return torch.npu.get_device_name(device)\n\n    def synchronize(self, device: Union[torch.device, int] = None):\n        \"\"\"\n        Synchronize the current process.\n        \"\"\"\n        torch.npu.synchronize(device)\n\n    def is_available(self):\n        \"\"\"\n        Check if the accelerator is available.\n        \"\"\"\n        return torch.npu.is_available()\n\n    def device_count(self):\n        \"\"\"\n        Return the number of devices on the machine.\n        \"\"\"\n        return torch.npu.device_count()\n\n    def get_device_capability(self, device=None) -> Tuple[int, int]:\n        \"\"\"\n        Gets the npu capability of a device.\n        \"\"\"\n        return torch.npu.get_device_capability(device)\n\n    def get_device_name(self, device=None) -> str:\n        \"\"\"\n        Gets the name of a device.\n        \"\"\"\n        return torch.npu.get_device_name(device)\n\n    def get_device_properties(self, device):\n        \"\"\"\n        Gets the properties of a device.\n        \"\"\"\n        return torch.npu.get_device_properties(device)\n\n    def utilization(self, device=None) -> int:\n        \"\"\"\n        Returns the percent of time over the past sample period during which one or more kernels was executing on the GPU as given by nvidia-smi\n        \"\"\"\n        return torch.npu.utilization(device)\n\n    # =======================\n    # random number generator APIs\n    # =======================\n    def get_rng_state(self, device=\"npu\") -> torch.Tensor:\n        \"\"\"\n        Returns the random number generator state of the specified GPU as a ByteTensor.\n        \"\"\"\n        return torch.npu.get_rng_state(device)\n\n    def get_rng_state_all(self) -> List[torch.Tensor]:\n        \"\"\"\n        Returns a list of ByteTensor representing the random number states of all devices.\n        \"\"\"\n        return torch.npu.get_rng_state_all()\n\n    def set_rng_state(self, new_state: torch.ByteTensor, device: str = \"npu\") -> None:\n        \"\"\"\n        Sets the random number generator state of the specified GPU.\n        \"\"\"\n        torch.npu.set_rng_state(new_state, device)\n\n    def set_rng_state_all(self, new_states: List[torch.ByteTensor]) -> None:\n        \"\"\"\n        Sets the random number generator state of all devices.\n        \"\"\"\n        torch.npu.set_rng_state_all(new_states)\n\n    def manual_seed(self, seed: int) -> None:\n        \"\"\"\n        Sets the seed for generating random numbers for the current GPU.\n        \"\"\"\n        torch.npu.manual_seed(seed)\n\n    def manual_seed_all(self, seed: int) -> None:\n        \"\"\"\n        Set the random seed for the all processes.\n        \"\"\"\n        torch.npu.manual_seed_all(seed)\n\n    def seed(self) -> None:\n        \"\"\"\n        Sets the seed for generating random numbers to a random number for the current GPU.\n        \"\"\"\n        torch.npu.seed()\n\n    def seed_all(self) -> None:\n        \"\"\"\n        Sets the seed for generating random numbers to a random number on all GPUs.\n        \"\"\"\n        torch.npu.seed_all()\n\n    def initial_seed(self) -> int:\n        \"\"\"\n        Returns the current random seed of the current GPU.\n        \"\"\"\n        return torch.npu.initial_seed()\n\n    # =======================\n    # memory management APIs\n    # =======================\n\n    def empty_cache(self) -> None:\n        \"\"\"\n        Releases all unoccupied cached memory currently held by the caching allocator so that those can be used in other GPU application and visible in nvidia-smi.\n        \"\"\"\n        torch.npu.empty_cache()\n\n    def memory_stats(self, device=None) -> Dict[str, Any]:\n        \"\"\"\n        Returns a dictionary of npu memory allocator statistics for a given device.\n        \"\"\"\n        return torch.npu.memory_stats(device=device)\n\n    def memory_summary(self, device=None, abbreviated=False) -> str:\n        \"\"\"\n        Returns a human-readable printout of the current memory allocator statistics for a given device.\n        \"\"\"\n        return torch.npu.memory_summary(device=device, abbreviated=abbreviated)\n\n    def memory_snapshot(self):\n        \"\"\"\n        Returns a snapshot of the npu memory allocator state across all devices.\n        \"\"\"\n        return torch.npu.memory_snapshot()\n\n    def memory_allocated(self, device=None) -> int:\n        \"\"\"\n        Returns the current GPU memory occupied by tensors in bytes for a given device.\n        \"\"\"\n        return torch.npu.memory_allocated(device=device)\n\n    def max_memory_allocated(self, device=None) -> int:\n        \"\"\"\n        Returns the maximum GPU memory occupied by tensors in bytes for a given device.\n        \"\"\"\n        return torch.npu.max_memory_allocated(device=device)\n\n    def reset_max_memory_allocated(self, device=None) -> None:\n        \"\"\"\n        Resets the starting point in tracking maximum GPU memory occupied by tensors for a given device.\n        \"\"\"\n        torch.npu.reset_max_memory_allocated(device=device)\n\n    def reset_max_memory_cached(self, device=None) -> None:\n        \"\"\"\n        Resets the starting point in tracking maximum GPU memory managed by the caching allocator for a given device.\n        \"\"\"\n        torch.npu.reset_max_memory_cached(device=device)\n\n    def memory_reserved(self, device=None) -> int:\n        \"\"\"\n        Returns the current GPU memory managed by the caching allocator in bytes for a given device.\n        \"\"\"\n        return torch.npu.memory_reserved(device=device)\n\n    def max_memory_reserved(self, device=None) -> int:\n        \"\"\"\n        Returns the maximum GPU memory managed by the caching allocator in bytes for a given device.\n        \"\"\"\n        return torch.npu.max_memory_reserved(device=device)\n\n    def set_per_process_memory_fraction(self, fraction: float, device=None) -> None:\n        \"\"\"\n        Set memory fraction for a process.\n        \"\"\"\n        torch.npu.set_per_process_memory_fraction(fraction, device=device)\n\n    def reset_peak_memory_stats(self, device=None) -> None:\n        \"\"\"\n        Resets the \"peak\" stats tracked by the npu memory allocator.\n        \"\"\"\n        torch.npu.reset_peak_memory_stats(device=device)\n\n    # =======================\n    # streams and events APIs\n    # =======================\n\n    def Stream(self, device=None, priority=0, **kwargs):\n        \"\"\"\n        A npu stream is a linear sequence of execution that belongs to a specific device, independent from other streams. See npu-semantics for details.\n        \"\"\"\n        return torch.npu.Stream(device, priority, **kwargs)\n\n    def Event(self, enable_timing: bool = False, blocking: bool = False, interprocess: bool = False):\n        \"\"\"\n        npu events are synchronization markers that can be used to monitor the device's progress, to accurately measure timing, and to synchronize npu streams.\n        \"\"\"\n        return torch.npu.Event(enable_timing, blocking, interprocess)\n\n    def current_stream(self, device=None):\n        \"\"\"\n        Returns the currently selected Stream for a given device.\n        \"\"\"\n        return torch.npu.current_stream(device)\n\n    def default_stream(self, device=None):\n        \"\"\"\n        Returns the default Stream for a given device.\n        \"\"\"\n        return torch.npu.default_stream(device)\n\n    def set_stream(self, stream_):\n        \"\"\"\n        Sets the current stream.This is a wrapper API to set the stream.\n        \"\"\"\n        torch.npu.set_stream(stream_)\n\n    def stream(self, stream_):\n        \"\"\"\n        Wrapper around the Context-manager StreamContext that selects a given stream.\n        \"\"\"\n        return torch.npu.stream(stream_)\n\n    # =======================\n    # amp APIs\n    # =======================\n    def autocast(\n        self, enabled: bool = True, dtype: torch.dtype = torch.float16, cache_enabled: bool = True\n    ) -> Callable:\n        \"\"\"\n        Return autocast function\n        \"\"\"\n        return torch.npu.amp.autocast(enabled=enabled, dtype=dtype, cache_enabled=cache_enabled)\n", "path": "colossalai/accelerator/npu_accelerator.py"}]}