mirror of
https://github.com/hpcaitech/ColossalAI.git
synced 2025-09-11 05:49:55 +00:00
[npu] change device to accelerator api (#5239)
* update accelerator * fix timer * fix amp * update * fix * update bug * add error raise * fix autocast * fix set device * remove doc accelerator * update doc * update doc * update doc * use nullcontext * update cpu * update null context * change time limit for example * udpate * update * update * update * [npu] polish accelerator code --------- Co-authored-by: Xuanlei Zhao <xuanlei.zhao@gmail.com> Co-authored-by: zxl <43881818+oahzxl@users.noreply.github.com>
This commit is contained in:
@@ -9,7 +9,8 @@ from typing import Any, Callable, List
|
||||
import torch
|
||||
import torch.multiprocessing as mp
|
||||
from packaging import version
|
||||
from colossalai.utils.device import empty_cache, reset_max_memory_allocated, reset_peak_memory_stats, synchronize, reset_max_memory_cached, device_count
|
||||
|
||||
from colossalai.accelerator import get_accelerator
|
||||
|
||||
|
||||
def parameterize(argument: str, values: List[Any]) -> Callable:
|
||||
@@ -199,7 +200,7 @@ def skip_if_not_enough_gpus(min_gpus: int):
|
||||
|
||||
def _wrap_func(f):
|
||||
def _execute_by_gpu_num(*args, **kwargs):
|
||||
num_avail_gpu = device_count()
|
||||
num_avail_gpu = get_accelerator().device_count()
|
||||
if num_avail_gpu >= min_gpus:
|
||||
f(*args, **kwargs)
|
||||
|
||||
@@ -263,11 +264,11 @@ def clear_cache_before_run():
|
||||
|
||||
def _wrap_func(f):
|
||||
def _clear_cache(*args, **kwargs):
|
||||
empty_cache()
|
||||
reset_peak_memory_stats()
|
||||
reset_max_memory_allocated()
|
||||
reset_max_memory_cached()
|
||||
synchronize()
|
||||
get_accelerator().empty_cache()
|
||||
get_accelerator().reset_peak_memory_stats()
|
||||
get_accelerator().reset_max_memory_allocated()
|
||||
get_accelerator().reset_max_memory_cached()
|
||||
get_accelerator().synchronize()
|
||||
gc.collect()
|
||||
f(*args, **kwargs)
|
||||
|
||||
|
Reference in New Issue
Block a user