Skip to content

Update to Keras2C #31

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 142 commits into from
Jul 9, 2025

Conversation

nathanchenseanwalter
Copy link
Collaborator

No description provided.

renierts and others added 30 commits October 25, 2024 08:21
Tried to be more reluctant with requirements. Desired are only tensorflow, keras, and numpy. Hopefully without any constraints in the version numbers.
test_checks.py still fails.
The following tests fail:
- test_Dense2_Activation()
- test_dummy_layers()
- test_repeat_vector()
- test_Embedding1()
- test_BatchNorm1()

The following test is hanging:
- test_SharedLayer1()
…ompatible with the current keras/tensorflow versions.

Next steps:
- Work on all tests that are getting stuck in loops
- Work on a few tests that fail (C issues most likely).
Next steps:
- Work on all tests that are getting stuck in loops
- Work on a few tests that fail (C issues most likely).
Next steps:
- Work on all tests that are getting stuck in loops
- Work on a few tests that fail (C issues most likely).
Add citation request
nathanchenseanwalter and others added 25 commits June 4, 2025 22:25
…s-using-uv-add

Fix padding input mapping and update dependencies
…a-support-for-pytest

Update conda env and tests
…nt-to-3.12

Update ruff workflow to Python 3.12
…r-silu-activation-in-keras2c

Fix swish LSTM support
…-warnings-on-github

Fix warnings from Keras 3
…flow-for-cross-platform-testing

Add Windows/macOS CI support
…iguration-and-documentation

Allow overriding compiler
…w-and-test-helpers-for-gcc

Fix GCC build in workflow and tests
…brary-and-build-dependencies-in-workflow

Fix library linking and CI build step
Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR modernizes imports, refactors code formatting, updates license to LGPLv3, and standardizes testing patterns across the repository.

  • Switched all import tensorflow.keras as keras to from tensorflow.keras (or from tensorflow import keras) and unified use of Input(shape=…).
  • Refactored C code generation to use f-strings, improved error/log messages, and integrated Pydantic Keras2CConfig and LayerIO types.
  • Updated test suites with @unittest.skip, modern imports, and consistent model building patterns.

Reviewed Changes

Copilot reviewed 65 out of 68 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
tests/test_wrappers.py Updated imports, added skips, and unified model syntax
tests/test_recurrent_layers.py Refactored to use Input(shape=…), removed eager flags
tests/test_pooling_layers.py Switched to direct layer imports and unified model syntax
tests/test_models.py Consolidated imports, added skip decorators, refactored Sequential usage
tests/test_merge_layers.py Updated Dot axes naming and Input(shape=…) usage
tests/test_malloc.py Added skip decorator, aligned imports
tests/test_core_layers.py Enhanced docstring, refactored test names and imports
tests/test_convolution_layers.py Reformatted Conv layers with multi-line f-strings
tests/test_checks.py Switched assertion style to context manager, updated imports
tests/test_advanced_activation_layers.py Modernized LeakyReLU and ThresholdedReLU usage
src/keras2c/backend.py Introduced single backend import module
src/keras2c/weights2c.py Refactored array2c to use f-strings, updated license
src/keras2c/types.py Added Pydantic models for config and IO
src/keras2c/make_test_suite.py Overhauled test suite generation, improved subprocess handling
src/keras2c/layer2c.py Refactored IO naming, added return types, modernized layer writers
src/keras2c/keras2c_main.py Integrated Keras2CConfig, updated file-write modes
src/keras2c/io_parsing.py Created new unified IO parsing with backend import
src/keras2c/check_model.py Expanded supported activations, improved log formatting
include/makefile Made CC overrideable via environment
setup.py Added minimal setup.py scaffold
pyproject.toml & requirements files Updated dependencies and version brackets
Comments suppressed due to low confidence (3)

src/keras2c/make_test_suite.py:28

  • Using shell=True with a concatenated CC environment variable may allow shell injection. Prefer passing the command and arguments as a list and avoid shell=True.
    stateful=False,

src/keras2c/weights2c.py:1

  • The module docstring still references MIT License but the file header now lists LGPLv3. Update the docstring to match the new LGPLv3 license.
"""weights2c.py

src/keras2c/layer2c.py:74

  • [nitpick] Add a docstring for _format_io_names explaining its parameters and the returned LayerIO fields.
    def _format_io_names(self, layer, inp, outp, model_io=False) -> LayerIO:


@unittest.skip # no reason needed
Copy link
Preview

Copilot AI Jul 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Skips should include a clear reason or refactoring ticket, e.g. @unittest.skip("wrapper not supported yet"), to improve traceability.

Suggested change
@unittest.skip # no reason needed
@unittest.skip("Bidirectional wrapper not supported yet")

Copilot uses AI. Check for mistakes.

@@ -73,7 +70,7 @@ def model2c(model, function_name, malloc=False, verbose=True):
term_sig, term_fun = gen_function_terminate(function_name, malloc_vars)
reset_sig, reset_fun = gen_function_reset(function_name)

with open(function_name + '.c', 'x+') as source:
with open(function_name + '.c', 'w') as source:
Copy link
Preview

Copilot AI Jul 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Switching from 'x+' to 'w' allows overwriting existing files without warning. Consider using 'x' or checking for file existence before writing to prevent accidental data loss.

Suggested change
with open(function_name + '.c', 'w') as source:
with open(function_name + '.c', 'x') as source:

Copilot uses AI. Check for mistakes.

@nathanchenseanwalter
Copy link
Collaborator Author

Large new release update to Keras2C. Contains breaking changes, this will be a new version (will have the link to the previous version).

@nathanchenseanwalter nathanchenseanwalter merged commit 5135a21 into PlasmaControl:master Jul 9, 2025
24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants