internlm/SWE-Fixer-Train-110K huggingface dataset:
Repository: keras-team/keras

Issue:
StringLookup does not return expected dtype for multi_hot
Documentation states we should expected float32 when using 'multi_hot', however int64 tensor is being returned

```print(f"tf version: {tf.__version__}")
vocab = ["a", "b", "c", "d"]
data = [["a", "c", "d", "d"], ["d", "z", "b", "z"]]
layer = tf.keras.layers.StringLookup(vocabulary=vocab, out
put_mode='multi_hot')
layer(data)```
```
tf version: 2.16.1
<tf.Tensor: shape=(2, 5), dtype=int64, numpy=
array([[0, 1, 0, 1, 1],
       [1, 0, 1, 0, 1]])>
```


Discussion:
Hi @Toku11 ,

I have tested the code snippets from APIs and the dtype should be int64 for the cases `output_mode` with `one_hot` `multi_hot` and `count` . The documentation needs to be changed to `int64` instead of `float32`. Thanks!



Resolving patch:
diff --git a/keras/src/layers/preprocessing/string_lookup.py b/keras/src/layers/preprocessing/string_lookup.py
--- a/keras/src/layers/preprocessing/string_lookup.py
+++ b/keras/src/layers/preprocessing/string_lookup.py
@@ -192,7 +192,7 @@ class StringLookup(IndexLookup):
            [0., 0., 1., 0., 0.],
            [0., 0., 0., 1., 0.],
            [0., 0., 0., 0., 1.],
-           [1., 0., 0., 0., 0.]], dtype=float32)
+           [1., 0., 0., 0., 0.]], dtype=int64)
 
     **Multi-hot output**
 
@@ -204,7 +204,7 @@ class StringLookup(IndexLookup):
     >>> layer = StringLookup(vocabulary=vocab, output_mode='multi_hot')
     >>> layer(data)
     array([[0., 1., 0., 1., 1.],
-           [1., 0., 1., 0., 1.]], dtype=float32)
+           [1., 0., 1., 0., 1.]], dtype=int64)
 
     **Token count output**
 
@@ -216,7 +216,7 @@ class StringLookup(IndexLookup):
     >>> layer = StringLookup(vocabulary=vocab, output_mode='count')
     >>> layer(data)
     array([[0., 1., 0., 1., 2.],
-           [2., 0., 1., 0., 1.]], dtype=float32)
+           [2., 0., 1., 0., 1.]], dtype=int64)
 
     **TF-IDF output**
 


Test patch:
Repository: keras-team/keras

Issue:
Unable to make two instances of the MobileNetV3 within the same model
I'm trying to use two distinct instances of mobilenet as sub-modules of one bigger model. 

This is the error I receive.
`ValueError: The name "MobilenetV3small" is used 2 times in the model. All operation names should be unique.`

For some weird reason, Keras does not handle name uniqueness automatically, nor does it give you the option to specify model name.
I've tested it on MobileNetV3Small specifically, but I guess it's the case for all other models within the `applications` API. 

See the code in a colab notebook below:

https://colab.research.google.com/drive/11R7m0yULUPhlN52ligdsPK18Mh6vKUCq?usp=sharing

P.S. I've tried to interface with `_name` attribute for each layer of the model, but it gets even worse from there, as it renders you unable to save the model throwing even more errors at you.


Discussion:
Thanks for the repro! Here's a smaller one:

```
x = keras.Input((None, None, 3))
out1 = keras.layers.Flatten(name='a')(x)
out2 = keras.layers.Flatten(name='a')(x)
keras.Model(inputs=x, outputs=[out1, out2])
```

I think when the layer or model name is hard-coded in a functional model (like it is [here for MobileNetV3](https://github.com/keras-team/keras/blob/da83683f5e92fa24a0ad7bf5dc034ea596346d21/keras/src/applications/mobilenet_v3.py#L376)), it won't be auto-deduplicated. I think the fix here is to remove the hard-coded name.

Resolving patch:
diff --git a/keras/src/applications/mobilenet_v3.py b/keras/src/applications/mobilenet_v3.py
--- a/keras/src/applications/mobilenet_v3.py
+++ b/keras/src/applications/mobilenet_v3.py
@@ -162,6 +162,7 @@ def MobileNetV3(
     dropout_rate=0.2,
     classifier_activation="softmax",
     include_preprocessing=True,
+    name=None,
 ):
     if not (weights in {"imagenet", None} or file_utils.exists(weights)):
         raise ValueError(
@@ -373,7 +374,7 @@ def MobileNetV3(
         inputs = img_input
 
     # Create model.
-    model = Functional(inputs, x, name="MobilenetV3" + model_type)
+    model = Functional(inputs, x, name=name)
 
     # Load weights.
     if weights == "imagenet":
@@ -412,6 +413,7 @@ def MobileNetV3Small(
     dropout_rate=0.2,
     classifier_activation="softmax",
     include_preprocessing=True,
+    name="MobileNetV3Small",
 ):
     def stack_fn(x, kernel, activation, se_ratio):
         def depth(d):
@@ -461,6 +463,7 @@ def depth(d):
         dropout_rate,
         classifier_activation,
         include_preprocessing,
+        name=name,
     )
 
 
@@ -477,6 +480,7 @@ def MobileNetV3Large(
     dropout_rate=0.2,
     classifier_activation="softmax",
     include_preprocessing=True,
+    name="MobileNetV3Large",
 ):
     def stack_fn(x, kernel, activation, se_ratio):
         def depth(d):
@@ -524,6 +528,7 @@ def depth(d):
         dropout_rate,
         classifier_activation,
         include_preprocessing,
+        name=name,
     )
 
 


Test patch:
Repository: hi-primus/optimus

Issue:
Fix simple typo: ouput -> output
# Issue Type

[x] Bug (Typo)

# Steps to Replicate

1. Examine optimus/ml/encoding.py.
2. Search for ouput.

# Expected Behaviour

1. Should read output.




Discussion:

Resolving patch:
diff --git a/optimus/ml/encoding.py b/optimus/ml/encoding.py
--- a/optimus/ml/encoding.py
+++ b/optimus/ml/encoding.py
@@ -35,7 +35,7 @@ def string_to_index(df, input_cols, output_cols=None, columns=None, **kargs):
     numeric, we cast it to string and index the string values.
     :param df: Dataframe to be transformed
     :param input_cols: Columns to be indexed.
-    :param output_cols:Column where the ouput is going to be saved
+    :param output_cols:Column where the output is going to be saved
     :return: Dataframe with indexed columns.
     """
     df_actual = df


Test patch:
Repository: hi-primus/optimus

Issue:
Json file exploration/profiling
Unstructured data as JSON can not be explored as regular tabular data. I have been exploring using tree depth and count to highlight the user in which nodes could have important data.

Some work in progress, here. https://github.com/ironmussa/Optimus/blob/develop-3.0/optimus/engines/pandas/io/json.py


Discussion:

Resolving patch:
diff --git a/optimus/engines/pandas/io/json.py b/optimus/engines/pandas/io/json.py
--- a/optimus/engines/pandas/io/json.py
+++ b/optimus/engines/pandas/io/json.py
@@ -121,7 +121,7 @@ def flatten(x, name=''):
                 result.append((_flatten_json(i)))
         elif is_dict(value):
             for i, j in value.items():
-                a = {"col": i}
+                a = {path: i}
                 a.update(_flatten_json(j))
                 result.append(a)
         return result


Test patch:
Repository: hi-primus/optimus

Issue:
Profiling bug when creating a dataframe from a dictionary using dask
**Describe the bug**
calling `df.profile("*")` for a dataframe created using `op.create.dataframe` causes an error `KeyError: 'id'`.

**To Reproduce**
```
df = op.create.dataframe({"id":[5,6,10,11,79,100]})
df.profile("*")
```



Discussion:

Resolving patch:
diff --git a/optimus/engines/base/dask/dataframe.py b/optimus/engines/base/dask/dataframe.py
--- a/optimus/engines/base/dask/dataframe.py
+++ b/optimus/engines/base/dask/dataframe.py
@@ -25,7 +25,13 @@ def _assign(self, kw_columns):
             for key in kw_columns:
                 kw_column = kw_columns[key]
                 if not is_one_element(kw_column) and not callable(kw_column) and not kw_column.known_divisions:
-                    kw_columns[key] = kw_column.reset_index().set_index('index')[key]
+                    _dfd = kw_column.reset_index().set_index('index')
+                    if key in _dfd:
+                        # the incoming series has the same column key
+                        kw_columns[key] = _dfd[key]
+                    else:
+                        # the incoming series has no column key
+                        kw_columns[key] = _dfd[0]
         return dfd.assign(**kw_columns)
 
     @staticmethod


Test patch:
Repository: huggingface/peft

Issue:
Can I give the number of steps to save the model file?
![image](https://user-images.githubusercontent.com/36957508/217777521-ece80a5c-01b7-4bc7-be43-099b8a0441fc.png)
When I am using the code below (red box area), The line 'accelerator.backward(loss) 'will report an error, and displays "**Element 0 of tensors does not require grad and does not have a grad_fn**"


Discussion:

Resolving patch:
diff --git a/src/peft/peft_model.py b/src/peft/peft_model.py
--- a/src/peft/peft_model.py
+++ b/src/peft/peft_model.py
@@ -98,9 +98,6 @@ def save_pretrained(self, save_directory, **kwargs):
             raise ValueError(f"Provided path ({save_directory}) should be a directory, not a file")
         os.makedirs(save_directory, exist_ok=True)
 
-        for param in self.parameters():
-            param.requires_grad = False  # freeze the model
-
         # save only the trainable weights
         output_state_dict = get_peft_model_state_dict(self, kwargs.get("state_dict", None))
         torch.save(output_state_dict, os.path.join(save_directory, WEIGHTS_NAME))
@@ -112,8 +109,10 @@ def save_pretrained(self, save_directory, **kwargs):
                 if isinstance(self.peft_config, PromptLearningConfig)
                 else self.base_model.model.__dict__.get("name_or_path", None)
             )
+        inference_mode = self.peft_config.inference_mode
         self.peft_config.inference_mode = True
         self.peft_config.save_pretrained(save_directory)
+        self.peft_config.inference_mode = inference_mode
 
     @classmethod
     def from_pretrained(cls, model, model_id, **kwargs):


Test patch:
Repository: huggingface/peft

Issue:
`PeftModel.disable_adapter()` context manager doesn't release on exception
[The `PeftModel.disable_adapter()` context manager](https://github.com/huggingface/peft/blob/49a20c16dcd9de5716feee717e8eb742efb9eff9/src/peft/peft_model.py#L299-L312) is misimplemented. Currently, it doesn't use `try` and `finally` inside:

```python
@contextmanager
def disable_adapter(self):
    """
    Disables the adapter module.
    """
    if isinstance(self.active_peft_config, PromptLearningConfig):
        old_forward = self.forward
        self.forward = self.base_model.forward
    else:
        self.base_model.disable_adapter_layers()
    yield
    if isinstance(self.active_peft_config, PromptLearningConfig):
        self.forward = old_forward
    else:
        self.base_model.enable_adapter_layers()
```

This works in the default normal case, but crucially fails to re-enable the adapter layers if an exception is raised while the context manager is active (e.g. a CUDA OOM error, in my case 🥲).

Instead, this context manager should use `try` and `finally` as shown [in the contextlib documentation](https://docs.python.org/3/library/contextlib.html):

```python
contextmanager
def disable_adapter(self):
    """
    Disables the adapter module.
    """
    try:
        if isinstance(self.peft_config, PromptLearningConfig):
            old_forward = self.forward
            self.forward = self.base_model.forward
        else:
            self.base_model.disable_adapter_layers()
        yield
    finally:
        if isinstance(self.peft_config, PromptLearningConfig):
            self.forward = old_forward
        else:
            self.base_model.enable_adapter_layers()
```

This appropriately catches exceptions and undoes the context manager (re-enabling the layers) in cases like:

```python
with peft_model.disable_adapter():
    ...
    raise Exception
````



Discussion:

Resolving patch:
diff --git a/src/peft/peft_model.py b/src/peft/peft_model.py
--- a/src/peft/peft_model.py
+++ b/src/peft/peft_model.py
@@ -300,16 +300,18 @@ def disable_adapter(self):
         """
         Disables the adapter module.
         """
-        if isinstance(self.active_peft_config, PromptLearningConfig):
-            old_forward = self.forward
-            self.forward = self.base_model.forward
-        else:
-            self.base_model.disable_adapter_layers()
-        yield
-        if isinstance(self.active_peft_config, PromptLearningConfig):
-            self.forward = old_forward
-        else:
-            self.base_model.enable_adapter_layers()
+        try:
+            if isinstance(self.peft_config, PromptLearningConfig):
+                old_forward = self.forward
+                self.forward = self.base_model.forward
+            else:
+                self.base_model.disable_adapter_layers()
+            yield
+        finally:
+            if isinstance(self.peft_config, PromptLearningConfig):
+                self.forward = old_forward
+            else:
+                self.base_model.enable_adapter_layers()
 
     def get_base_model(self):
         """


Test patch:
Repository: huggingface/peft

Issue:
importing peft with an old version of bitsandbytes causes an exception
### System Info

Importing peft with the bitsandbytes version "0.39.1" works. But when importing peft with the version "0.38.1", I get an exception : `AttributeError: module 'bitsandbytes.nn' has no attribute 'Linear4bit'`.

Indeed, the class `SVDLinear4bit` should be defined only if `is_bnb_4bit_available()`, not just if `is_bnb_available()`.

### Who can help?

_No response_

### Information

- [ ] The official example scripts
- [ ] My own modified scripts

### Tasks

- [ ] An officially supported task in the `examples` folder
- [ ] My own task or dataset (give details below)

### Reproduction

in a notebook :
!pip install 'bitsandbytes==0.38.1'
import peft

### Expected behavior

no exception


Discussion:
@younesbelkada This issue seems important if you plan a new release.
thanks for the ping @glerzing 
Did https://github.com/huggingface/peft/pull/605 not fixed the issue? can you confirm you get that even with the main branch of PEFT?
That PR introduced a stronger check, and should be using the `is_bnb_4bit_available` method: https://github.com/huggingface/peft/blob/f5352f08c593503a442f4438e1c7e648377b6a4b/src/peft/tuners/adalora.py#L11 

Resolving patch:
diff --git a/src/peft/tuners/adalora.py b/src/peft/tuners/adalora.py
--- a/src/peft/tuners/adalora.py
+++ b/src/peft/tuners/adalora.py
@@ -523,6 +523,9 @@ def forward(self, x: torch.Tensor):
                 result = result + output
             return result
 
+
+if is_bnb_4bit_available():
+
     class SVDLinear4bit(bnb.nn.Linear4bit, AdaLoraLayer):
         # Low-rank matrix for SVD-based adaptation
         def __init__(


Test patch:
Repository: huggingface/peft

Issue:
Support Tensor Parallelism, which is used in LLaMA-2
### Feature request

[`transformers`'s LLaMA-2 implementation](https://github.com/huggingface/transformers/pull/24891) can bypass adapters because it directly split linear weight as `self.q_proj.weight.split` when Tensor Parallelism is enabled. Ideally, adapters should be split accordingly

https://github.com/huggingface/transformers/blob/476be08c4aa96f8c1cae4200d2677bbe8f12cf80/src/transformers/models/llama/modeling_llama.py#L291

### Motivation

To support LLaMA-2

### Your contribution

Discussion, reviewing a PR or submitting a PR


Discussion:

Resolving patch:
diff --git a/src/peft/peft_model.py b/src/peft/peft_model.py
--- a/src/peft/peft_model.py
+++ b/src/peft/peft_model.py
@@ -119,6 +119,12 @@ def __init__(self, model: PreTrainedModel, peft_config: PeftConfig, adapter_name
         if getattr(model, "is_gradient_checkpointing", True):
             model = self._prepare_model_for_gradient_checkpointing(model)
 
+        # the `pretraining_tp` is set for some models to simulate Tensor Parallelism during inference to avoid
+        # numerical differences, https://github.com/pytorch/pytorch/issues/76232 - to avoid any unexpected
+        # behavior we disable that in this line.
+        if hasattr(self.base_model, "config") and hasattr(self.base_model.config, "pretraining_tp"):
+            self.base_model.config.pretraining_tp = 1
+
     def save_pretrained(
         self,
         save_directory: str,


Test patch:
Repository: huggingface/peft

Issue:
`bitsandbytes` is imported eagerly in `peft/utils/loftq_utils.py`
https://github.com/huggingface/peft/pull/1230 makes the import of `bitsandbytes` lazy, however, the fix seems to be imcomplete.
https://github.com/huggingface/peft/blob/5a4b9cade64bac8afdff5006ee9dd815c90b5469/src/peft/utils/loftq_utils.py#L34-L35
Perhaps there can be a test case ensuring that the CUDA context is not initialized after importing `peft`, e.g.:
```python
import torch
import peft
assert not torch.cuda.is_initialized()
```
@BenjaminBossan 


Discussion:
Thanks for pointing this out, we can surely work on this, as it's a valid concern. Let us know if you're interested in creating a PR to fix this.
Hello, I can make a PR, but perhaps one month later. Is that okay?
Thanks! I'll hopefully have time to fix this earlier, as it's a bit annoying and should only require a few extra lines for the fix and test. If I don't find the time by then, I'll be happy to accept your PR.

Resolving patch:
diff --git a/src/peft/utils/loftq_utils.py b/src/peft/utils/loftq_utils.py
--- a/src/peft/utils/loftq_utils.py
+++ b/src/peft/utils/loftq_utils.py
@@ -31,10 +31,6 @@
 from peft.import_utils import is_bnb_4bit_available, is_bnb_available
 
 
-if is_bnb_available():
-    import bitsandbytes as bnb
-
-
 class NFQuantizer:
     def __init__(self, num_bits=2, device="cuda", method="normal", block_size=64, *args, **kwargs):
         super().__init__(*args, **kwargs)
@@ -192,6 +188,11 @@ def _low_rank_decomposition(weight, reduced_rank=32):
 
 @torch.no_grad()
 def loftq_init(weight: Union[torch.Tensor, torch.nn.Parameter], num_bits: int, reduced_rank: int, num_iter=1):
+    if is_bnb_available():
+        import bitsandbytes as bnb
+    else:
+        raise ValueError("bitsandbytes is not available, please install it to use LoftQ.")
+
     if num_bits not in [2, 4, 8]:
         raise ValueError("Only support 2, 4, 8 bits quantization")
     if num_iter <= 0:
@@ -239,6 +240,8 @@ def loftq_init(weight: Union[torch.Tensor, torch.nn.Parameter], num_bits: int, r
 
 @torch.no_grad()
 def _loftq_init_new(qweight, weight, num_bits: int, reduced_rank: int):
+    import bitsandbytes as bnb
+
     if num_bits != 4:
         raise ValueError("Only 4 bit quantization supported at the moment.")
     if not is_bnb_4bit_available():


Test patch:
Repository: SickChill/sickchill

Issue:
Fix Issue 43 - pythonw fails on Windows
fixes issue SickRage/sickrage-issues#43



Discussion:
lol im too tired for this shit :)

I will make a PR for it later that closes this one =P


Resolving patch:
diff --git a/SickBeard.py b/SickBeard.py
--- a/SickBeard.py
+++ b/SickBeard.py
@@ -152,7 +152,7 @@ def start(self):
 
         # pylint: disable=E1101
         if not sickbeard.SYS_ENCODING or sickbeard.SYS_ENCODING.lower() in ('ansi_x3.4-1968', 'us-ascii', 'ascii', 'charmap') or \
-            (sys.platform.startswith('win') and sys.getwindowsversion()[0] >= 6 and getattr(sys.stdout, 'device', sys.stdout).encoding.lower() in ('cp65001', 'charmap')):
+            (sys.platform.startswith('win') and sys.getwindowsversion()[0] >= 6 and str(getattr(sys.stdout, 'device', sys.stdout).encoding).lower() in ('cp65001', 'charmap')):
             sickbeard.SYS_ENCODING = 'UTF-8'
 
         # TODO: Continue working on making this unnecessary, this hack creates all sorts of hellish problems


Test patch:
Repository: scikit-hep/pyhf

Issue:
Add binderexample/StatisticalAnalysis.ipynb to docs examples
At the moment the Binder example notebook `binderexample/StatisticalAnalysis.ipynb` is not being included in the build of the docs. Lukas has put some really nice examples in there and it would be nice to have this in the docs in the even that people don't check out the Binder.

# Relevant Issues and Pull Requests

This is also somewhat relevant to Issue #168 



Discussion:
https://github.com/diana-hep/pyhf/blob/master/docs/conf.py#L94-L97
Sure, I guess I should have said "We currently intentionally ignore these. Is there a reason we do so?"
yeah, wasn't sure why we had two diff directories. But nothing in binderexample is tested.
I assume it was just to make it really clear what extra stuff was just for the Binder? Okay, good to know there isn't a technical case to ignore. :+1: 

Resolving patch:
diff --git a/docs/conf.py b/docs/conf.py
--- a/docs/conf.py
+++ b/docs/conf.py
@@ -94,7 +94,7 @@
 # List of patterns, relative to source directory, that match files and
 # directories to ignore when looking for source files.
 # This patterns also effect to html_static_path and html_extra_path
-exclude_patterns = ['_build', '**.ipynb_checkpoints', 'examples/experiments', 'examples/notebooks/binderexample']
+exclude_patterns = ['_build', '**.ipynb_checkpoints', 'examples/experiments']
 
 # The reST default role (used for this markup: `text`) to use for all
 # documents.


Test patch:
Repository: scikit-hep/pyhf

Issue:
Add pyhf talks section to README
Now that [Lukas has given the first talk on pyhf](https://indico.cern.ch/event/702612/contributions/2958658/) :+1:  it might be nice to have a "Talks and Presentations" section towards the bottom of the README where we link to this and future talks.

Example:
[
## Presentations on pyhf
- Lukas Heinrich, "[pyhf: A standalone HistFactory Implementation](https://indico.cern.ch/event/702612/contributions/2958658/)", (Re)interpreting the results of new physics searches at the LHC Workshop, CERN, May 15, 2018

]

Thoughts?



Discussion:
absolutely!
https://sphinxcontrib-bibtex.readthedocs.io/en/latest/quickstart.html#minimal-example ?

Resolving patch:
diff --git a/docs/conf.py b/docs/conf.py
--- a/docs/conf.py
+++ b/docs/conf.py
@@ -37,6 +37,7 @@
     'sphinx.ext.ifconfig',
     'sphinx.ext.viewcode',
     'sphinx.ext.githubpages',
+    'sphinxcontrib.bibtex',
     'sphinxcontrib.napoleon',
     'nbsphinx',
 ]
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -37,6 +37,7 @@
        'mxnet>=1.0.0',
        'graphviz',
        'sphinx',
+       'sphinxcontrib-bibtex',
        'sphinxcontrib-napoleon',
        'sphinx_rtd_theme',
        'nbsphinx',


Test patch:
Repository: scikit-hep/pyhf

Issue:
Updated setup.py for pytorch > 0.4 dependency
# Description

I had 0.3.1 for Torch and that caused issues with some of the doctesting as the distributions did not have `cdf` methods. I forced an upgrade pytorch and things are fine now.


Discussion:

Resolving patch:
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -9,7 +9,7 @@
   packages = find_packages(),
   include_package_data = True,
   install_requires = [
-    'numpy>=1.14.3',
+    'numpy<=1.14.5,>=1.14.3',  # required by tensorflow, mxnet, and us
     'scipy'
   ],
   extras_require = {
@@ -17,10 +17,18 @@
        'uproot',
      ],
     'torch': [
-      'torch'
+      'torch>=0.4.0'
     ],
     'mxnet':[
-      'mxnet',
+      'mxnet>=1.0.0',
+      'requests<2.19.0,>=2.18.4',
+      'numpy<1.15.0,>=1.8.2',
+      'requests<2.19.0,>=2.18.4',
+    ],
+    'tensorflow':[
+       'tensorflow==1.10.0',
+       'numpy<=1.14.5,>=1.13.3',
+       'setuptools<=39.1.0',
     ],
     'develop': [
        'pyflakes',
@@ -28,13 +36,11 @@
        'pytest-cov>=2.5.1',
        'pytest-benchmark[histogram]',
        'python-coveralls',
+       'coverage==4.0.3',  # coveralls
        'matplotlib',
        'jupyter',
        'uproot',
        'papermill',
-       'torch',
-       'tensorflow',
-       'mxnet>=1.0.0',
        'graphviz',
        'sphinx',
        'sphinxcontrib-bibtex',


Test patch: