Repository: pytorch
Issue: cpu log1p for bfloat16 gives wrong result.
Labels: module: cpu,triaged,module: bfloat16

### 🐛 Describe the bug

cpu log1p for bfloat16 gives inf on big number.

```
>>> import torch
>>> x = torch.tensor(1.821e+38).bfloat16()
>>> x
tensor(1.8210e+38, dtype=torch.bfloat16)
>>> x.log1p()
tensor(inf, dtype=torch.bfloat16)
>>> x = torch.tensor(1.821e+38).bfloat16().cuda()
>>> x.log1p()
tensor(88., device='cuda:0', dtype=torch.bfloat16)
```

### Versions

I'm on upstream master commit:
```
commit 59c1b5025f64f9a8ce87fc96b738fbbbb1191d91 (HEAD -> master, origin/master, origin/HEAD)
Author: Jerry Zhang <jerryzh168@gmail.com>
Date:   Mon Feb 6 10:45:04 2023 -0800

    [quant][fx][pt2e] Refactor prepare so it's aligned better with the new API plan in pt2e (#94011)
    
    Summary:
    There are three things that happens in the current prepare code,
    (1). user express their intention of how they want the model to be quantized with QConfigMapping, we translate that to
    node.meta["target_dtype_info"]
    (2). we validate the setting against BackendConfig
    (3). insert observers based on the validated node.meta["target_dtype_info"]
    
    previously (2) and (3) are mixed together, this PR tries to move (2) closer to (1), with one edge case left, this refactor
    moves us closer to our target design for quantization in pytorch 2.0 export path
    
    this is a follow up PR for https://github.com/pytorch/pytorch/pull/92641
    
    Test Plan:
    python test/test_quantization.py TestQuantizeFx
    python test/test_quantization.py TestQuantizeFxOps
    python test/test_quantization.py TestQuantizeFxModels
    
    Reviewers:
    
    Subscribers:
    
    Tasks:
    
    Tags:
    Pull Request resolved: https://github.com/pytorch/pytorch/pull/94011
    Approved by: https://github.com/vkuzo

```

```
root@d446ac0a67d7:/opt/pytorch/pytorch# python collect_env.py
Collecting environment information...
PyTorch version: 2.0.0a0+git59c1b50
Is debug build: False
CUDA used to build PyTorch: 12.0
ROCM used to build PyTorch: N/A

OS: Ubuntu 20.04.5 LTS (x86_64)
GCC version: (Ubuntu 9.4.0-1ubuntu1~20.04.1) 9.4.0
Clang version: Could not collect
CMake version: version 3.25.2
Libc version: glibc-2.31

Python version: 3.10.9 (main, Feb  7 2023, 00:37:12) [GCC 9.4.0] (64-bit runtime)
Python platform: Linux-5.4.0-126-generic-x86_64-with-glibc2.31
Is CUDA available: True
CUDA runtime version: 12.0.140
CUDA_MODULE_LOADING set to: LAZY
GPU models and configuration: GPU 0: NVIDIA A100 80GB PCIe
Nvidia driver version: 525.85.05
cuDNN version: Probably one of the following:
/usr/lib/x86_64-linux-gnu/libcudnn.so.8.7.0
/usr/lib/x86_64-linux-gnu/libcudnn_adv_infer.so.8.7.0
/usr/lib/x86_64-linux-gnu/libcudnn_adv_train.so.8.7.0
/usr/lib/x86_64-linux-gnu/libcudnn_cnn_infer.so.8.7.0
/usr/lib/x86_64-linux-gnu/libcudnn_cnn_train.so.8.7.0
/usr/lib/x86_64-linux-gnu/libcudnn_ops_infer.so.8.7.0
/usr/lib/x86_64-linux-gnu/libcudnn_ops_train.so.8.7.0
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: True

CPU:
Architecture:                    x86_64 
CPU op-mode(s):                  32-bit, 64-bit
Byte Order:                      Little Endian
Address sizes:                   43 bits physical, 48 bits virtual
CPU(s):                          64
On-line CPU(s) list:             0-63   
Thread(s) per core:              2
Core(s) per socket:              32
Socket(s):                       1
NUMA node(s):                    1
Vendor ID:                       AuthenticAMD
CPU family:                      23
Model:                           49
Model name:                      AMD Ryzen Threadripper PRO 3975WX 32-Cores
Stepping:                        0
Frequency boost:                 enabled
CPU MHz:                         2062.854
CPU max MHz:                     3500.0000
CPU min MHz:                     2200.0000
BogoMIPS:                        6987.16
Virtualization:                  AMD-V
L1d cache:                       1 MiB
L1i cache:                       1 MiB
L2 cache:                        16 MiB
L3 cache:                        128 MiB
NUMA node0 CPU(s):               0-63
Vulnerability Itlb multihit:     Not affected
Vulnerability L1tf:              Not affected
Vulnerability Mds:               Not affected
Vulnerability Meltdown:          Not affected
Vulnerability Mmio stale data:   Not affected
Vulnerability Spec store bypass: Vulnerable
Vulnerability Spectre v1:        Vulnerable: __user pointer sanitization and usercopy barriers only; no swapgs barriers
Vulnerability Spectre v2:        Vulnerable, IBPB: disabled, STIBP: disabled
Vulnerability Srbds:             Not affected
Vulnerability Tsx async abort:   Not affected
Flags:                           fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx mmxext fxsr_opt pdpe1gb rdtscp lm constant_tsc rep_good nopl nonstop_tsc cpuid extd_apicid aperfmperf pni pclmulqdq monitor ssse3 fma cx16 sse4_1 sse4_2 x2apic movbe popcnt aes xsave avx f16c rdrand lahf_lm cmp_legacy svm extapic cr8_legacy abm sse4a misalignsse 3dnowprefetch osvw ibs skinit wdt tce topoext perfctr_core perfctr_nb bpext perfctr_llc mwaitx cpb cat_l3 cdp_l3 hw_pstate sme ssbd mba sev ibpb stibp vmmcall fsgsbase bmi1 avx2 smep bmi2 cqm rdt_a rdseed adx smap clflushopt clwb sha_ni xsaveopt xsavec xgetbv1 xsaves cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local clzero irperf xsaveerptr wbnoinvd arat npt lbrv svm_lock nrip_save tsc_scale vmcb_clean flushbyasid decodeassists pausefilter pfthreshold avic v_vmsave_vmload vgif umip rdpid overflow_recov succor smca

Versions of relevant libraries:
[pip3] numpy==1.23.5
[pip3] torch==2.0.0a0+git59c1b50
[pip3] torchvision==0.15.0a0+85983a5
[conda] Could not collect
```

cc @jgong5 @mingfeima @XiaobingSuper @sanchitintel @ashokei @jingxu10