Skip to content

Commit 0ccd6bc

Browse files
committed
Merge branch 'master' into mlx
2 parents cc2f446 + 3b92b67 commit 0ccd6bc

File tree

274 files changed

+13300
-2776
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

274 files changed

+13300
-2776
lines changed

.github/workflows/actions.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ jobs:
4949
run: |
5050
pip install -r requirements.txt --progress-bar off --upgrade
5151
pip uninstall -y keras keras-nightly
52+
pip install tf_keras==2.16.0rc0 --progress-bar off --upgrade
5253
pip install -e "." --progress-bar off --upgrade
5354
- name: Test applications with pytest
5455
if: ${{ steps.filter.outputs.applications == 'true' }}
@@ -62,11 +63,13 @@ jobs:
6263
env_vars: PYTHON,KERAS_HOME
6364
flags: keras.applications,keras.applications-${{ matrix.backend }}
6465
files: apps-coverage.xml
66+
token: ${{ secrets.CODECOV_TOKEN }}
6567
fail_ci_if_error: false
6668
- name: Test integrations
6769
if: ${{ matrix.backend != 'numpy'}}
6870
run: |
6971
python integration_tests/import_test.py
72+
python integration_tests/numerical_test.py
7073
- name: Test TF-specific integrations
7174
if: ${{ matrix.backend == 'tensorflow'}}
7275
run: |
@@ -85,6 +88,7 @@ jobs:
8588
env_vars: PYTHON,KERAS_HOME
8689
flags: keras,keras-${{ matrix.backend }}
8790
files: core-coverage.xml
91+
token: ${{ secrets.CODECOV_TOKEN }}
8892
fail_ci_if_error: false
8993

9094
format:

.github/workflows/labeler.yaml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Copyright 2024 Google LLC. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
16+
# This workflow automatically identifies issues and pull requests (PRs) and add the
17+
# appropriate label as per defined rules.
18+
# First Labeler workflow: It searches for the keyword "Gemma" (case-insensitive) in both the title
19+
# and description of the issue/PR. If a match is found, the workflow adds the label 'Gemma' to the issue/PR.
20+
21+
name: 'Labeler'
22+
on:
23+
issues:
24+
types: [edited,opened]
25+
pull_request_target:
26+
types: [opened, edited]
27+
28+
permissions:
29+
contents: read
30+
issues: write
31+
pull-requests: write
32+
33+
jobs:
34+
welcome:
35+
runs-on: ubuntu-latest
36+
steps:
37+
- uses: actions/checkout@v4
38+
- uses: actions/github-script@v7
39+
with:
40+
script: |
41+
const script = require('./\.github/workflows/scripts/labeler.js')
42+
script({github, context})

.github/workflows/scorecard.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,6 @@ jobs:
5656

5757
# Upload the results to GitHub's code scanning dashboard.
5858
- name: "Upload to code-scanning"
59-
uses: github/codeql-action/upload-sarif@e8893c57a1f3a2b659b6b55564fdfdbbd2982911 # v3.24.0
59+
uses: github/codeql-action/upload-sarif@1b1aada464948af03b950897e5eb522f92603cc2 # v3.24.9
6060
with:
6161
sarif_file: results.sarif

.github/workflows/scripts/labeler.js

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
Copyright 2024 Google LLC. All Rights Reserved.
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
7+
http://www.apache.org/licenses/LICENSE-2.0
8+
9+
Unless required by applicable law or agreed to in writing, software
10+
distributed under the License is distributed on an "AS IS" BASIS,
11+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
See the License for the specific language governing permissions and
13+
limitations under the License.
14+
*/
15+
16+
17+
/**
18+
* Invoked from labeler.yaml file to add
19+
* label 'Gemma' to the issue and PR for which have gemma keyword present.
20+
* @param {!Object.<string,!Object>} github contains pre defined functions.
21+
* context Information about the workflow run.
22+
*/
23+
24+
module.exports = async ({ github, context }) => {
25+
const issue_title = context.payload.issue ? context.payload.issue.title : context.payload.pull_request.title
26+
const issue_discription = context.payload.issue ? context.payload.issue.body : context.payload.pull_request.body
27+
const issue_number = context.payload.issue ? context.payload.issue.number : context.payload.pull_request.number
28+
const keyword_label = {
29+
gemma:'Gemma'
30+
}
31+
const labelsToAdd = []
32+
console.log(issue_title,issue_discription,issue_number)
33+
34+
for(const [keyword, label] of Object.entries(keyword_label)){
35+
if(issue_title.toLowerCase().indexOf(keyword) !=-1 || issue_discription.toLowerCase().indexOf(keyword) !=-1 ){
36+
console.log(`'${keyword}'keyword is present inside the title or description. Pushing label '${label}' to row.`)
37+
labelsToAdd.push(label)
38+
}
39+
}
40+
if(labelsToAdd.length > 0){
41+
console.log(`Adding labels ${labelsToAdd} to the issue '#${issue_number}'.`)
42+
github.rest.issues.addLabels({
43+
owner: context.repo.owner,
44+
repo: context.repo.repo,
45+
issue_number: context.issue.number,
46+
labels: labelsToAdd
47+
})
48+
}
49+
};

.kokoro/github/ubuntu/gpu/build.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ pip install -U psutil
2626
if [ "$KERAS_BACKEND" == "tensorflow" ]
2727
then
2828
echo "TensorFlow backend detected."
29-
pip install -r requirements-tensorflow-cuda.txt --progress-bar off
29+
pip install -r requirements-tensorflow-cuda.txt --progress-bar off --timeout 1000
3030
pip uninstall -y keras keras-nightly
3131
echo "Check that TensorFlow uses GPU"
3232
python3 -c 'import tensorflow as tf;print(tf.__version__);print(tf.config.list_physical_devices("GPU"))'
@@ -42,7 +42,7 @@ fi
4242
if [ "$KERAS_BACKEND" == "jax" ]
4343
then
4444
echo "JAX backend detected."
45-
pip install -r requirements-jax-cuda.txt --progress-bar off
45+
pip install -r requirements-jax-cuda.txt --progress-bar off --timeout 1000
4646
pip uninstall -y keras keras-nightly
4747
python3 -c 'import jax;print(jax.__version__);print(jax.default_backend())'
4848
# Raise error if GPU is not detected.
@@ -62,7 +62,7 @@ fi
6262
if [ "$KERAS_BACKEND" == "torch" ]
6363
then
6464
echo "PyTorch backend detected."
65-
pip install -r requirements-torch-cuda.txt --progress-bar off
65+
pip install -r requirements-torch-cuda.txt --progress-bar off --timeout 1000
6666
pip uninstall -y keras keras-nightly
6767
python3 -c 'import torch;print(torch.__version__);print(torch.cuda.is_available())'
6868
# Raise error if GPU is not detected.

README.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
# Keras 3: Deep Learning for Humans
22

3-
Keras 3 is a multi-backend deep learning framework, with support for TensorFlow, JAX, and PyTorch.
3+
Keras 3 is a multi-backend deep learning framework, with support for JAX, TensorFlow, and PyTorch.
4+
Effortlessly build and train models for computer vision, natural language processing, audio processing,
5+
timeseries forecasting, recommender systems, etc.
6+
7+
- **Accelerated model development**: Ship deep learning solutions faster thanks to the high-level UX of Keras
8+
and the availability of easy-to-debug runtimes like PyTorch or JAX eager execution.
9+
- **State-of-the-art performance**: By picking the backend that is the fastest for your model architecture (often JAX!),
10+
leverage speedups ranging from 20% to 350% compared to other frameworks. [Benchmark here](https://keras.io/getting_started/benchmarks/).
11+
- **Datacenter-scale training**: Scale confidently from your laptop to large clusters of GPUs or TPUs.
12+
13+
Join nearly three million developers, from burgeoning startups to global enterprises, in harnessing the power of Keras 3.
14+
415

516
## Installation
617

SECURITY.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,66 @@
11
# Security Policy
22

3+
- [**Using Keras Securely**](#using-keras-securely)
4+
- [Untrusted inputs](#untrusted-inputs)
5+
- [Data privacy](#data-privacy)
6+
- [Untrusted environments or networks](#untrusted-environments-or-networks)
7+
- [Multi-Tenant environments](#multi-tenant-environments)
8+
- [**Reporting a Vulnerability**](#reporting-a-vulnerability)
9+
10+
## Using Keras Securely
11+
12+
### Untrusted inputs
13+
14+
Some models accept various input formats (text, images, audio, etc.). The libraries converting these inputs have varying security levels, so it's crucial to isolate the model and carefully pre-process inputs to mitigate script injection risks.
15+
16+
For maximum security when handling untrusted inputs, you may need to employ the following:
17+
18+
* Sandboxing: Isolate the model process.
19+
* Pre-analysis: check how the model performs by default when exposed to prompt injection (e.g. using [fuzzing for prompt injection](https://github.com/FonduAI/awesome-prompt-injection?tab=readme-ov-file#tools)). This will give you leads on how hard you will have to work on the next topics.
20+
* Updates: Keep your model and libraries updated with the latest security patches.
21+
* Input Sanitation: Before feeding data to the model, sanitize inputs rigorously. This involves techniques such as:
22+
* Validation: Enforce strict rules on allowed characters and data types.
23+
* Filtering: Remove potentially malicious scripts or code fragments.
24+
* Encoding: Convert special characters into safe representations.
25+
* Verification: Run tooling that identifies potential script injections (e.g. [models that detect prompt injection attempts](https://python.langchain.com/docs/guides/safety/hugging_face_prompt_injection)).
26+
27+
### Data privacy
28+
To protect sensitive data from potential leaks or unauthorized access, it is essential to sandbox the model execution. This means running the model in a secure, isolated environment, which helps mitigate many attack vectors.
29+
30+
When training the model with sensitive data, expose your newly-trained model to tests to identify potential sensitive data leaks.
31+
32+
### Untrusted environments or networks
33+
34+
If you can't run your models in a secure and isolated environment or if it must be exposed to an untrusted network, make sure to take the following security precautions:
35+
* Confirm the hash of any downloaded artifact (i.e. pre-trained model weights) matches a known-good value
36+
* Encrypt your data while sending it over the network.
37+
38+
### Multi-Tenant environments
39+
40+
If you intend to run multiple models in parallel with shared memory, it is your responsibility to ensure the models do not interact or access each other's data. The primary areas of concern are tenant isolation, resource allocation, model sharing and hardware attacks.
41+
42+
#### Tenant Isolation
43+
44+
You must make sure that models run separately. Since models can run code, it's important to use strong isolation methods to prevent unwanted access to the data from other tenants.
45+
46+
Separating networks is also a big part of isolation. If you keep model network traffic separate, you not only prevent unauthorized access to data or models, but also prevent malicious users or tenants sending graphs to execute under another tenant’s identity.
47+
48+
#### Resource Allocation
49+
50+
A denial of service caused by one model can impact the overall system health. Implement safeguards like rate limits, access controls, and health monitoring.
51+
52+
#### Model Sharing
53+
54+
In a multitenant design that allows sharing models, make sure that tenants and users fully understand the potential security risks involved. They must be aware that they will essentially be running code provided by other users. Unfortunately, there are no reliable methods available to detect malicious models, graphs, or checkpoints. To mitigate this risk, the recommended approach is to sandbox the model execution, effectively isolating it from the rest of the system.
55+
56+
#### Hardware Attacks
57+
58+
Besides the virtual environment, the hardware (GPUs or TPUs) can also be attacked. [Research](https://scholar.google.com/scholar?q=gpu+side+channel) has shown that side channel attacks on GPUs are possible, which can make data leak from other models or processes running on the same system at the same time.
59+
60+
## Reporting a Vulnerability
61+
62+
Beware that none of the topics under [Using Keras Securely](#using-Keras-securely) are considered vulnerabilities of Keras.
63+
364
If you have discovered a security vulnerability in this project, please report it
465
privately. **Do not disclose it as a public issue.** This gives us time to work with you
566
to fix the issue before public exposure, reducing the chance that the exploit will be

guides/custom_train_step_in_jax.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ def metrics(self):
277277
outputs = keras.layers.Dense(1)(inputs)
278278
model = CustomModel(inputs, outputs)
279279

280-
# We don't passs a loss or metrics here.
280+
# We don't pass a loss or metrics here.
281281
model.compile(optimizer="adam")
282282

283283
# Just use `fit` as usual -- you can use callbacks, etc.

guides/custom_train_step_in_tensorflow.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ def metrics(self):
189189
outputs = keras.layers.Dense(1)(inputs)
190190
model = CustomModel(inputs, outputs)
191191

192-
# We don't passs a loss or metrics here.
192+
# We don't pass a loss or metrics here.
193193
model.compile(optimizer="adam")
194194

195195
# Just use `fit` as usual -- you can use callbacks, etc.

guides/custom_train_step_in_torch.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ def metrics(self):
204204
outputs = keras.layers.Dense(1)(inputs)
205205
model = CustomModel(inputs, outputs)
206206

207-
# We don't passs a loss or metrics here.
207+
# We don't pass a loss or metrics here.
208208
model.compile(optimizer="adam")
209209

210210
# Just use `fit` as usual -- you can use callbacks, etc.

0 commit comments

Comments
 (0)