Freeze zero weights during training
@sampathrajapaksha,
Could you please elaborate about your Feature. Also, please specify the Use Cases for this feature. Thank you! @tilakrayal 
This is related to TF pruning. Even though TF provides the model pruning capability, it lacks retraining pruning models. 
I have pruned a model up to 80% .  If I want to retrain the algorithm only using non-pruned weights (Non-zero weights), there's no way to achieve this in TF. 
Might be 0,1 masks can be used to convert gradients to zero for pruned weights, But, this introduces additional calculation, and therefore it's not computationally efficient. 
Is there any way to calculate gradients only for non-zero weights and retrain unpruned weights efficiently?  Hi @sampathrajapaksha ,

Could you please refer to this model_optimization documentation related to model pruning [here](https://www.tensorflow.org/model_optimization/guide/pruning) and an [example](https://www.tensorflow.org/model_optimization/guide/pruning/pruning_with_keras) here. 
This will help us in reducing model size at cost of Accuracy.Please let us know if this is helpful. 

If your requirement is different please provide gist of an end to end example which helps us to evaluate this feature.

Thanks! This issue is stale because it has been open for 7 days with no activity. It will be closed if no further activity occurs. Thank you. This issue was closed because it has been inactive for 7 days since being marked as stale. Please reopen if you'd like to work on this further.
<details><summary>Click to expand!</summary> 
 
 ### Issue Type

Feature Request

### Have you reproduced the bug with TF nightly?

Yes

### Source

source

### Tensorflow Version

2.11

### Custom Code

Yes

### OS Platform and Distribution

_No response_

### Mobile device

_No response_

### Python version

_No response_

### Bazel version

_No response_

### GCC/Compiler version

_No response_

### CUDA/cuDNN version

_No response_

### GPU model and memory

_No response_

### Current Behaviour?

```shell
Is there any way to freeze zero weights during model retraining? (this is different than freezing a layer which is already available in TF)
This is relevant to model pruning. For example, i want to retrain only non-zero weights of a pruned model. Is it possible to use tf.IndexedSlices efficiently for this?
```


### Standalone code to reproduce the issue

```shell
I think we can achieve this if there's any feature in TF to calculate grads only for non-zero weights. I couldn't find any method to achieve this 

@tf.function
def train_step(inputs, targets):
    with tf.GradientTape() as tape:
       predictions = model(inputs, training=True)
       loss_value = loss_fn(targets, predictions)
    grads = tape.gradient(loss_value, model.trainable_weights)
    optimizer.apply_gradients(zip(grads, model.trainable_weights))
    return loss_value
```


### Relevant log output

_No response_</details>