Update generation_logits_process.py
Author: willfrey
Pull request: yes

# What does this PR do?

If you're using type hints, then passing an `int` where a `float` is annotated is acceptable as per [PEP 484](https://www.python.org/dev/peps/pep-0484/#the-numeric-tower).

This makes life a little nicer.

<!--
Congratulations! You've made it this far! You're not quite done yet though.

Once merged, your PR is going to appear in the release notes with the title you set, so make sure it's a great title that fully reflects the extent of your awesome contribution.

Then, please replace this with a description of the change and which issue is fixed (if applicable). Please also include relevant motivation and context. List any dependencies (if any) that are required for this change.

Once you're done, someone will review your PR shortly (see the section "Who can review?" below to tag some potential reviewers). They may suggest changes to make the code even better. If no one reviewed your PR after a week has passed, don't hesitate to post a new comment @-mentioning the same persons---sometimes notifications get lost.
-->

<!-- Remove if not applicable -->

~Fixes # (issue)~


## Before submitting
- [x] Did you read the [contributor guideline](https://github.com/huggingface/transformers/blob/master/CONTRIBUTING.md#start-contributing-pull-requests),
      Pull Request section?


## Who can review?

Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.

<!-- Your PR will be replied to more quickly if you can figure out the right person to tag with @

 If you know how to use git blame, that is the easiest way, otherwise, here is a rough guide of **who to tag**.
 Please tag fewer than 3 people.

Models:

- albert, bert, xlm: @LysandreJik
- blenderbot, bart, marian, pegasus, encoderdecoder,  t5: @patrickvonplaten, @patil-suraj
- longformer, reformer, transfoxl, xlnet: @patrickvonplaten
- fsmt: @stas00
- funnel: @sgugger
- gpt2: @patrickvonplaten, @LysandreJik
- rag: @patrickvonplaten, @lhoestq
- tensorflow: @LysandreJik

Library:

- benchmarks: @patrickvonplaten
- deepspeed: @stas00
- ray/raytune: @richardliaw, @amogkam
- text generation: @patrickvonplaten
- tokenizers: @n1t0, @LysandreJik
- trainer: @sgugger
- pipelines: @LysandreJik

Documentation: @sgugger

HF projects:

- datasets: [different repo](https://github.com/huggingface/datasets)
- rust tokenizers: [different repo](https://github.com/huggingface/tokenizers)

Examples:

- maintained examples (not research project or legacy): @sgugger, @patil-suraj
- research_projects/bert-loses-patience: @JetRunner
- research_projects/distillation: @VictorSanh

 -->


Comments:
Hi @willfrey, I've merged many of your PRs (thanks for that 🤗) but I don't agree with this one since there is no integer between 0 and 1 so it'll be nice to have the instance check here (in case someone passes a tensor or something).

I’d suggest checking against numbers.Integral then because that’s the ABC/protocol for anything like an integer.

> On Jul 29, 2021, at 3:38 PM, Kevin Canwen Xu ***@***.***> wrote:
> 
> ﻿
> Hi @willfrey, I've merged many of your PRs but I don't agree with this one since there is no integer between 0 and 1 so it'll be nice to have the instance check here (in case someone passes a tensor or something).
> 
> —
> You are receiving this because you were mentioned.
> Reply to this email directly, view it on GitHub, or unsubscribe.


Sorry, not numbers.Integral but numbers.Real. 

I'm just trying to not have it raise an exception if I pass in `1` instead of `1.0` because I can't rely on passing `None` to default to `1.0` because it may be overridden by a model's config.

I can change it so that it checks against that and won't yell at you for passing a `1`, if you'd prefer.

> I'm just trying to not have it raise an exception if I pass in `1` instead of `1.0` because I can't rely on passing `None` to default to `1.0` because it may be overridden by a model's config.
> 
> I can change it so that it checks against that and won't yell at you for passing a `1`, if you'd prefer.

Hi @willfrey I checked again and I think the best solution is to add a try-except for the typecasting `float()`. If it throws an exception we should catch it and tell the users you should pass a number

Sure, I’ll make that change!

> On Jul 30, 2021, at 10:49 AM, Kevin Canwen Xu ***@***.***> wrote:
> 
> ﻿
> I'm just trying to not have it raise an exception if I pass in 1 instead of 1.0 because I can't rely on passing None to default to 1.0 because it may be overridden by a model's config.
> 
> I can change it so that it checks against that and won't yell at you for passing a 1, if you'd prefer.
> 
> Hi @willfrey I checked again and I think the best solution is to add a try-except for the typecasting float(). If it throws an exception we should catch it and tell the users you should pass a number
> 
> —
> You are receiving this because you were mentioned.
> Reply to this email directly, view it on GitHub, or unsubscribe.


This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread.

Please note that issues that do not follow the [contributing guidelines](https://github.com/huggingface/transformers/blob/master/CONTRIBUTING.md) are likely to be ignored.

@willfrey Hi, could you make the change as we discussed? I'm pinging again since the stale bot is pinging.

Hi @JetRunner.

Sorry, had this drop off my radar.

Do we want to re-raise an exception from just calling `float(top_p)`? That'll throw a `TypeError` if whatever the original `top_p` parameter does not support being an argument to `float(...)`.

It'd basically be:

```py3
try:
    top_p = float(top_p)
except TypeError:
    raise TypeError(f"cannot interpret {top_p!r} as a float")
```

which seems a little redundant.

Happy to make the change if you want, though.

You made a point! I'll just merge it as it is now.