Skip to content

Commit

Permalink
fix imports & pytest
Browse files Browse the repository at this point in the history
  • Loading branch information
chhwang committed Aug 14, 2024
1 parent 4cca609 commit 45b14b8
Show file tree
Hide file tree
Showing 17 changed files with 37 additions and 45 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ build/
*.pyc
*.pyo
*.pyd
.pytest_cache/

# Git
**/.git
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ jobs:
- name: Build
run: |
mkdir build && cd build
cmake -DCMAKE_BUILD_TYPE=Debug -DARK_BUILD_PYTHON=ON -DARK_BYPASS_GPU_CHECK=ON -DARK_USE_CUDA=ON -DARK_BUILD_TESTS=OFF ..
cmake -DCMAKE_BUILD_TYPE=Debug -DARK_BYPASS_GPU_CHECK=ON -DARK_USE_CUDA=ON -DARK_BUILD_TESTS=OFF ..
make build ark_py
- name: Perform CodeQL Analysis
Expand Down Expand Up @@ -95,7 +95,7 @@ jobs:
- name: Build
run: |
mkdir build && cd build
CXX=/opt/rocm/bin/hipcc cmake -DCMAKE_BUILD_TYPE=Debug -DARK_BUILD_PYTHON=ON -DARK_BYPASS_GPU_CHECK=ON -DARK_USE_ROCM=ON -DARK_BUILD_TESTS=OFF ..
CXX=/opt/rocm/bin/hipcc cmake -DCMAKE_BUILD_TYPE=Debug -DARK_BYPASS_GPU_CHECK=ON -DARK_USE_ROCM=ON -DARK_BUILD_TESTS=OFF ..
make -j build ark_py
- name: Perform CodeQL Analysis
Expand Down
8 changes: 6 additions & 2 deletions .github/workflows/ut-cuda.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:
- name: Build
run: |
mkdir build && cd build
cmake -DCMAKE_BUILD_TYPE=Debug -DARK_BUILD_PYTHON=ON ..
cmake -DCMAKE_BUILD_TYPE=Debug ..
make -j ut ark_py
- name: Run C++ UT
Expand All @@ -71,7 +71,11 @@ jobs:
- name: Run Python UT
run: |
cd build
ARK_ROOT=$PWD pytest --cov=../python/ark --cov-report lcov:py_coverage.info --verbose ../python/unittest/test.py
PYTHONPATH=$PWD/python ARK_ROOT=$PWD python3 -m pytest \
--cov=../python/ark \
--cov-report lcov:py_coverage.info \
--verbose \
../python/unittest/test.py
- name: Report Coverage
env:
Expand Down
5 changes: 4 additions & 1 deletion python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ FetchContent_MakeAvailable(pybind11)

file(GLOB_RECURSE BIND_SOURCES CONFIGURE_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp)
pybind11_add_module(ark_py ${BIND_SOURCES})
set_target_properties(ark_py PROPERTIES OUTPUT_NAME _ark_core)
set_target_properties(ark_py PROPERTIES OUTPUT_NAME _ark_core LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/ark)
add_custom_command(TARGET ark_py POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/ark ${CMAKE_CURRENT_BINARY_DIR}/ark
)
target_link_libraries(ark_py PRIVATE ark_static)
target_include_directories(ark_py SYSTEM PRIVATE ${DLPACK_INCLUDE_DIRS})
target_include_directories(ark_py PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../ark)
Expand Down
10 changes: 1 addition & 9 deletions python/ark/__init__.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.

import sys
import os

if os.environ.get("ARK_ROOT", None) is None:
os.environ["ARK_ROOT"] = os.path.abspath(os.path.dirname(__file__))

sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))

import _ark_core
from . import _ark_core

Check warning on line 9 in python/ark/__init__.py

View check run for this annotation

Codecov / codecov/patch

python/ark/__init__.py#L9

Added line #L9 was not covered by tests
from .model import Model


Expand All @@ -21,11 +18,6 @@ def version():
return __version__


def srand(seed):
"""Sets the seed for random number generation."""
_ark_core.srand(seed)


def set_rank(rank):
"""Sets the rank of the current process."""
Model.set_rank(rank)
Expand Down
2 changes: 1 addition & 1 deletion python/ark/data_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Licensed under the MIT license.

import numpy
import _ark_core
from . import _ark_core

try:
import torch
Expand Down
16 changes: 8 additions & 8 deletions python/ark/error.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.

from _ark_core import _BaseError as BaseError
from _ark_core import _InternalError as InternalError
from _ark_core import _InvalidUsageError as InvalidUsageError
from _ark_core import _ModelError as ModelError
from _ark_core import _PlanError as PlanError
from _ark_core import _UnsupportedError as UnsupportedError
from _ark_core import _SystemError as SystemError
from _ark_core import _GpuError as GpuError
from ._ark_core import _BaseError as BaseError
from ._ark_core import _InternalError as InternalError
from ._ark_core import _InvalidUsageError as InvalidUsageError
from ._ark_core import _ModelError as ModelError
from ._ark_core import _PlanError as PlanError
from ._ark_core import _UnsupportedError as UnsupportedError
from ._ark_core import _SystemError as SystemError
from ._ark_core import _GpuError as GpuError

Check warning on line 11 in python/ark/error.py

View check run for this annotation

Codecov / codecov/patch

python/ark/error.py#L4-L11

Added lines #L4 - L11 were not covered by tests

__all__ = [
"BaseError",
Expand Down
2 changes: 1 addition & 1 deletion python/ark/init.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.

import _ark_core
from . import _ark_core

Check warning on line 4 in python/ark/init.py

View check run for this annotation

Codecov / codecov/patch

python/ark/init.py#L4

Added line #L4 was not covered by tests
from .model import Model
from .runtime import _RuntimeState

Expand Down
2 changes: 1 addition & 1 deletion python/ark/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Licensed under the MIT license.

from typing import NewType
from _ark_core import _Model
from ._ark_core import _Model

_ModelState = NewType("_ModelState", None)

Expand Down
2 changes: 1 addition & 1 deletion python/ark/planner.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import json
from typing import Callable, Dict, List, Any

from _ark_core import _Planner, _PlannerContext
from ._ark_core import _Planner, _PlannerContext

Check warning on line 8 in python/ark/planner.py

View check run for this annotation

Codecov / codecov/patch

python/ark/planner.py#L8

Added line #L8 was not covered by tests
from .model import Model


Expand Down
2 changes: 1 addition & 1 deletion python/ark/runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import logging
from enum import Enum

from _ark_core import _Executor
from ._ark_core import _Executor

Check warning on line 7 in python/ark/runtime.py

View check run for this annotation

Codecov / codecov/patch

python/ark/runtime.py#L7

Added line #L7 was not covered by tests
from .planner import Planner, Plan


Expand Down
2 changes: 1 addition & 1 deletion python/ark/tensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import numpy as np
from typing import Callable, List, Union, Type

Check warning on line 5 in python/ark/tensor.py

View check run for this annotation

Codecov / codecov/patch

python/ark/tensor.py#L5

Added line #L5 was not covered by tests

from _ark_core import _Dims, _Tensor, _NullTensor
from ._ark_core import _Dims, _Tensor, _NullTensor

Check warning on line 7 in python/ark/tensor.py

View check run for this annotation

Codecov / codecov/patch

python/ark/tensor.py#L7

Added line #L7 was not covered by tests
from .data_type import DataType
from .runtime import Runtime
from .model import Model

Check warning on line 10 in python/ark/tensor.py

View check run for this annotation

Codecov / codecov/patch

python/ark/tensor.py#L10

Added line #L10 was not covered by tests
Expand Down
6 changes: 0 additions & 6 deletions python/unittest/test.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.

import sys
import os

sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)) + "/..")
sys.path.insert(0, os.environ.get("ARK_ROOT", ".") + "/python")

from test_error import *
from test_model import *
from test_runtime import *
Expand Down
4 changes: 2 additions & 2 deletions python/unittest/test_error.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.

import ark
from unittest_common import ark, pytest_ark


@pytest_ark()
def test_error():
ark.init()
try:
ark.tensor([0])
except ark.BaseError as e:
Expand Down
5 changes: 2 additions & 3 deletions python/unittest/test_model.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.

import ark
from unittest_common import ark, pytest_ark
import json


@pytest_ark()
def test_model():
ark.init()

input_tensor = ark.tensor([64, 64], ark.fp16)
other_tensor = ark.tensor([64, 64], ark.fp16)
ark.add(input_tensor, other_tensor)
Expand Down
8 changes: 4 additions & 4 deletions python/unittest/test_runtime.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.

import ark
from unittest_common import ark, pytest_ark
import numpy as np


@pytest_ark()
def test_runtime_relaunch():
ark.init()
with ark.Runtime.get_runtime() as rt:
assert rt.launched() == False
rt.launch()
Expand All @@ -18,8 +18,8 @@ def test_runtime_relaunch():
assert rt.launched() == True


@pytest_ark()
def test_runtime_init():
ark.init()
M, N = 64, 64
input_tensor = ark.tensor([M, N], ark.fp16)
other_tensor = ark.tensor([M, N], ark.fp16)
Expand Down Expand Up @@ -51,8 +51,8 @@ def test_runtime_init():
runtime.reset()


@pytest_ark()
def test_runtime_reuse_plans():
ark.init()
M, N = 64, 64
input_tensor = ark.tensor([M, N], ark.fp16)
other_tensor = ark.tensor([M, N], ark.fp16)
Expand Down
3 changes: 1 addition & 2 deletions python/unittest/test_tensor.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.

from unittest_common import pytest_ark
import ark
from unittest_common import ark, pytest_ark


@pytest_ark(need_torch=True)
Expand Down

0 comments on commit 45b14b8

Please sign in to comment.