Skip to content

Commit

Permalink
qemu system mode (#1201)
Browse files Browse the repository at this point in the history
* close non-equal split

* fix typeinfer of conv2d

* fix fold binary

* do not swap binary args

* update setup.py

* do not pre-preprocess onnx with external data

* imgnore .mono in git

* restore SwapBinaryArgs

* fix onnx test runner

---------

Co-authored-by: sunnycase <sunnycase@live.cn>
  • Loading branch information
xhuohai and sunnycase committed May 7, 2024
1 parent a2869fa commit 482b761
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 9 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -307,3 +307,6 @@ cmake-build-*
*.ipynb_checkpoints*
# Auto generated files
# generated/

.mono/
.history/
2 changes: 1 addition & 1 deletion conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def requirements(self):
self.requires('rapidjson/1.1.x')

if self.options.python:
self.requires('pybind11/2.6.1')
self.requires('pybind11/2.12.0')

if not self.options.runtime:
self.requires('abseil/20220623.1')
Expand Down
5 changes: 2 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,7 @@ def run(self):
os.walk(os.path.join(bin_dir, 'sharplibs')) for _lib in files if
os.path.isfile(os.path.join(root, _lib)) and
(os.path.splitext(_lib)[-1] in [".dll", ".so", ".dylib", ".json"] or
_lib.startswith("lib"))
and not _lib.endswith(".deps.json")]
_lib.startswith("lib"))]

for lib in sharp_libs:
shutil.move(lib, os.path.join(self.build_dir,
Expand Down Expand Up @@ -204,7 +203,7 @@ def build_cmake(self, ext: Extension):
extdir += os.path.sep

bin_dir = os.path.abspath(os.path.join(self.build_temp, 'install'))
cmake_args = ['-G', 'Ninja', '-DDOTNET_INIT_FOR_CONFIG=ON']
cmake_args = ['-G', 'Ninja', '-DDOTNET_INIT_FOR_CONFIG=OFF']
if platform.system() == 'Windows':
cmake_args += ['-DCMAKE_C_COMPILER=clang-cl']
cmake_args += ['-DCMAKE_CXX_COMPILER=clang-cl']
Expand Down
6 changes: 3 additions & 3 deletions src/Nncase.Core/Utilities/DistributedUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public static IReadOnlyList<IRArray<SBP>> GetLeafCandidateNDSBPs(TensorType tens
var ndsbp = new List<SBP>();
for (int axis = 0; axis < tensorType.Shape.Rank; axis++)
{
if (tensorType.Shape[axis] is { IsFixed: true, Value: int s } && IsDivideBy(s, placement.Hierarchy[i]))
if (tensorType.Shape[axis] is { IsFixed: true, Value: int s } && IsDivideExactly(s, placement.Hierarchy[i]))
{
ndsbp.Add(SBP.S(axis));
}
Expand Down Expand Up @@ -50,7 +50,7 @@ public static IReadOnlyList<IRArray<SBP>> GetPartialCandidateNDSBPs(DistributedT
candidateNdsbps[i].Add(SBP.B);
for (int axis = 0; axis < tensorType.Shape.Rank; axis++)
{
if (tensorType.Shape[axis] is { IsFixed: true, Value: int s } && IsDivideBy(s, placement.Hierarchy[i]) && !innerSplitedAxes.Contains(axis))
if (tensorType.Shape[axis] is { IsFixed: true, Value: int s } && IsDivideExactly(s, placement.Hierarchy[i]) && !innerSplitedAxes.Contains(axis))
{
candidateNdsbps[i].Add(SBP.S(axis));
}
Expand All @@ -73,7 +73,7 @@ public static bool IsDistributable(TensorType tensorType, ReadOnlySpan<SBP> ndsb
}

var divisors = GetDivisors(new DistributedType(tensorType, new IRArray<SBP>(ndsbp.ToArray()), placement));
return divisors.Select((d, axis) => (d, axis)).All(p => p.d == 0 ? true : IsDivideBy(tensorType.Shape[p.axis].FixedValue, p.d));
return divisors.Select((d, axis) => (d, axis)).All(p => p.d == 0 ? true : IsDivideExactly(tensorType.Shape[p.axis].FixedValue, p.d));
}

public static IReadOnlyList<int> GetDivisors(DistributedType distributedType)
Expand Down
2 changes: 1 addition & 1 deletion src/Nncase.Evaluator/NN/Conv2D.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ private IRType Visit(ITypeInferenceContext context, Conv2D target, DistributedTy
return new InvalidType(string.Empty);
}

if (input.Placement != weights.Placement)
if (input.Placement != weights.Placement || input.Placement != bias.Placement)
{
return new InvalidType("placement not equal");
}
Expand Down
5 changes: 4 additions & 1 deletion tests/onnx_test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,13 @@ def run(self, model_file):
elif model_file.startswith('onnx-models'):
model_file = os.path.join(os.getenv('ONNX_MODELS_DIR'),
model_file[len('onnx-models/'):])
has_external_data = False
if self.case_dir != os.path.dirname(model_file):
new_file = os.path.join(self.case_dir, 'test.onnx')
shutil.copy(model_file, new_file)
for tensor in external_data_helper._get_all_tensors(onnx.load(model_file, load_external_data=False)):
if external_data_helper.uses_external_data(tensor):
has_external_data = True
info = external_data_helper.ExternalDataInfo(tensor)
file_location = external_data_helper._sanitize_path(info.location)
external_data_src_path = os.path.join(
Expand All @@ -76,7 +78,8 @@ def run(self, model_file):
if not self.inputs:
self.parse_model(model_file)

model_file = self.do_preprocess(model_file)
if not has_external_data:
model_file = self.do_preprocess(model_file)

super().run(model_file)

Expand Down

0 comments on commit 482b761

Please sign in to comment.