Open ChinChangYang opened 8 months ago
Regarding with the AttributeError
, it can be fixed by the following diff for the coremltools
source code:
% git diff --cached coremltools
diff --git a/coremltools/converters/mil/mil/ops/defs/iOS15/elementwise_unary.py b/coremltools/converters/mil/mil/ops/defs/iOS15/elementwise_unary.py
index c5ebc40..fb6902f 100644
--- a/coremltools/converters/mil/mil/ops/defs/iOS15/elementwise_unary.py
+++ b/coremltools/converters/mil/mil/ops/defs/iOS15/elementwise_unary.py
@@ -890,7 +890,7 @@ class cast(Operation):
return np.array(result)
return None
- if not types.is_tensor(input_var.sym_type):
- return input_var.val.astype(dtype=string_to_nptype(dtype_val))
- else:
+ if isinstance(input_var.val, float) or types.is_tensor(input_var.sym_type):
return np.array(input_var.val).astype(dtype=string_to_nptype(dtype_val))
+ else:
+ return input_var.val.astype(dtype=string_to_nptype(dtype_val))
I am running coremltools
test suites. I will create a pull request in coremltools
GitHub repository. If the pull request is accepted, hopefully a new coremltools
release includes this fix.
Test 2: 512x19 (PASSED)
% python net_to_coreml.py --cfg 512x19-t80.yaml-20230507-0216 512x19-t81-swa-10061000.pb.gz
TensorFlow version 2.15.0 has not been tested with coremltools. You may run into unexpected errors. TensorFlow 2.12.0 is the most recent version that has been tested.
dataset:
allow_less_chunks: true
input_test:
- dev1/test/
input_train:
- dev1/train/
input_validation: dev1/validate/
num_chunks: 3000000
test_workers: 8
train_ratio: 0.9
train_workers: 32
gpu: 0
model:
default_activation: mish
filters: 512
pol_encoder_layers: 0
policy: attention
residual_blocks: 19
se_ratio: 16
name: 512x19-t80
training:
batch_size: 1024
checkpoint_steps: 4000
diff_focus_min: 0.025
diff_focus_slope: 3.0
lookahead_optimizer: true
lr_boundaries:
- 100
lr_values:
- 0.0004
- 0.0004
mask_legal_moves: true
max_grad_norm: 4.0
moves_left_loss_weight: 1.0
num_batch_splits: 2
num_test_positions: 40000
path: dev1/networks
policy_loss_weight: 1.0
q_ratio: 0.0
reg_term_weight: 0.05
renorm: true
renorm_max_d: 0.0
renorm_max_r: 1.0
shuffle_size: 500000
swa: true
swa_max_n: 10
swa_output: true
swa_steps: 100
test_steps: 500
total_steps: 500
train_avg_report_steps: 200
validation_steps: 500
value_loss_weight: 1.0
warmup_steps: 1000
[PhysicalDevice(name='/physical_device:GPU:0', device_type='GPU')]
/Users/chinchangyang/miniconda3/envs/lczero-training-py3.11/lib/python3.11/site-packages/tensorflow_addons/utils/tfa_eol_msg.py:23: UserWarning:
TensorFlow Addons (TFA) has ended development and introduction of new features.
TFA has entered a minimal maintenance and release mode until a planned end of life in May 2024.
Please modify downstream libraries to take dependencies from other repositories in our TensorFlow community (e.g. Keras, Keras-CV, and Keras-NLP).
For more information see: https://github.com/tensorflow/addons/issues/2807
warnings.warn(
Wrote model to dev1/networks/512x19-t80/512x19-t80-0
Running TensorFlow Graph Passes: 100%|█████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 6/6 [00:00<00:00, 9.77 passes/s]
Converting TF Frontend ==> MIL Ops: 100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████| 987/987 [00:00<00:00, 13041.75 ops/s]
Running MIL frontend_tensorflow2 pipeline: 100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████| 7/7 [00:00<00:00, 788.02 passes/s]
Running MIL default pipeline: 100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 71/71 [00:03<00:00, 20.14 passes/s]
Running MIL backend_mlprogram pipeline: 100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████| 12/12 [00:00<00:00, 805.74 passes/s]
Input names: ['input_planes']
Output names: ['output_policy', 'output_value', 'output_moves_left']
Rebuilding model with updated spec ...
Saving model ...
CoreML model saved at dev1/networks/512x19-t80/512x19-t81-swa-10061000.pb.gz.mlpackage
The AttributeError
has been resolved in https://github.com/apple/coremltools/pull/2087.
Unable to convert the 11248.pb.gz
net into a model by net_to_model.py
. The issue has been described in https://github.com/LeelaChessZero/lczero-training/issues/224.
This commit introduces the
net_to_coreml.py
script in thetf/
directory. The script facilitates the conversion of a neural network file into a TensorFlow model, followed by its transformation into a CoreML model. This process mirrors the TensorFlow model conversion methodology used innet_to_model.py
.Key features of the CoreML conversion include:
input_planes
as the input name.output_policy
,output_value
, andoutput_moves_left
.Lc0 converted from {net name}
. The script concludes by saving the CoreML model as{net name}.mlpackage
. This enhancement enables the conversion of neural networks into CoreML models, which can be executed using Apple's Neural Engine. Future development of the CoreML backend is planned within thelc0
repository.Test 1: 128x10 (PASS)
Test 2: 512x19 (FAILED)
The error message is similar with this issue. https://github.com/apple/coremltools/issues/1768