-
Notifications
You must be signed in to change notification settings - Fork 5.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Typing][PEP585 Upgrade] PEP 585 标准集合泛型支持升级——Python 3.8 退场前瞻特别任务 #66936
Labels
PFCC
Paddle Framework Contributor Club,https://github.com/PaddlePaddle/community/tree/master/pfcc
status/close
已关闭
type/others
其他问题
Comments
SigureMo
changed the title
[Typing][PEP585 Upgrade] PEP 585 标准库泛型支持升级——Python 3.8 退场前瞻任务
[Typing][PEP585 Upgrade] PEP 585 标准集合泛型支持升级——Python 3.8 退场前瞻任务
Aug 1, 2024
SigureMo
changed the title
[Typing][PEP585 Upgrade] PEP 585 标准集合泛型支持升级——Python 3.8 退场前瞻任务
[Typing][PEP585 Upgrade] PEP 585 标准集合泛型支持升级——Python 3.8 退场前瞻特别任务
Aug 1, 2024
paddle-bot
bot
added
the
PFCC
Paddle Framework Contributor Club,https://github.com/PaddlePaddle/community/tree/master/pfcc
label
Aug 1, 2024
python 3.8 至 python 3.9 类型标注映射表
|
【报名】:1 |
【报名】:100-150 |
【报名】:151-200 |
【报名】:201-260 |
【报名】:51-100 |
【报名】:4-50 |
This was referenced Aug 5, 2024
This was referenced Aug 7, 2024
This was referenced Aug 7, 2024
This was referenced Aug 7, 2024
This was referenced Aug 7, 2024
22 tasks
[Typing][PEP585 Upgrade] PEP 585 标准集合泛型支持升级——Python 3.8 退场前瞻特别任务 已全部完成,感谢参与的小伙伴们!
|
github-project-automation
bot
moved this from In Progress
to Done
in Call for Contributions
Aug 13, 2024
16 tasks
21 tasks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
PFCC
Paddle Framework Contributor Club,https://github.com/PaddlePaddle/community/tree/master/pfcc
status/close
已关闭
type/others
其他问题
任务背景
此次任务为 为 Paddle 框架 API 添加类型提示(Type Hints) 以及 Python 版本退场中 Ruff 升级部分的联合企划。
Python 3.8 EOL 在即1,是时候开始考虑 Python 3.8 退场的一些事情了。但是先别急,正式退场还需要一段时间,但我们可以考虑一些现阶段可以做的事情了~
自引入 Ruff 以来,每退场一个旧版本时必做的事情就是调整
target-version
了,我们现在所使用的target-version
是py38
,也就是表明我们最低支持的 Python 版本是 3.8。当然,在我们正式退场 3.8 时需要将其调整为py39
。经过简单的测试,我们发现升级 py39 居然有 1000 多个问题需要修复,这么庞大的数量对于我们退场 3.8 来说是有一点小小的阻力的
一般来说,只有真正能退场 3.8 的时候才可以修复这些问题,因为这些问题是 3.9 引入了一些新特性,而 3.8 并不支持……但我们这次的报错是有一些不同的,这里的报错基本都是 PEP 585 的升级问题,即使用类似
list
、collections.abc.Sequence
这种标准泛型来替代typing.List
、typing.Sequence
这种泛型,虽然直接使用仍然会报错,但是 PEP 585 明确提到了,如果使用 PEP 563(即from __future__ import annotations
),那么我们是可以在「类型注解语义」下使用这些标准泛型的。而刚好,我们的类型提示本就是将使用 PEP 563 作为规范的一部分的,因此我们完全可以在当前还支持 3.8 的情况下,通过使用 PEP 563,在「类型注解语义」的 case 下,来修复 PEP 585 弃用掉的类型因此本次希望与大家一起推动 PEP 585 升级,退场掉大部分弃用的 typing 泛型使用
任务目标
让我们来看看具体要怎么做吧~
示例一
修改为
Note
一定要在文件开头加上
from __future__ import annotations
,否则如上所述,这在 3.8 下会报错的哦~如果不清楚使用方式, 请搜索仓库中存量的
from __future__ import annotations
来查看使用方法。示例二
修改为
示例三
如果需要替换的对象出现在 「非类型注解语义」 的场景下不能进行修改, 如果一个文件所有 case 都处于「非类型注解语义」下,请在本 issue 评论区留言或在提交 PR 时指出即可。
当然我们大多数类型提示都是在「类型注解语义」下使用的,「非类型注解语义」下使用的很少,所以大多数可以放心替换~
你也可以参考 PR #66941 来查看一个完整的 PR 大概要如何修改
实施步骤
安装 ruff v0.5.0
首先我们需要能够复现这 1000 多个问题,首先就需要自己安装一下 Ruff
目前 paddle 所使用的 ruff 版本为 0.5.0,请使用相同版本确保问题的可复现性:
$ pip install ruff==0.5.0
问题复现
以
python/paddle/tensor/linalg.py
为例UP035 为错误码,可以参考「示例二」进行修改,也可以在 ruff rules 查找错误码对应的规则。
Note
PEP 585 只对应 UP006 和 UP035 两条 rule,如果遇到 UP036 则直接跳过,当前 Python 3.8 未退场的情况下无法提前修复 UP036
任务列表
paddle/fluid/ir_adaptor/translator/op_compat_gen.py
paddle/fluid/operators/generator/filters.py
paddle/fluid/operators/generator/parse_utils.py
paddle/fluid/pir/dialect/op_generator/ops_onednn_extra_parser.py
paddle/phi/api/generator/api_base.py
paddle/phi/kernels/fusion/cutlass/memory_efficient_attention/generate_kernels.py
paddle/phi/kernels/fusion/cutlass/memory_efficient_attention/generate_variable_forward_kernels.py
python/paddle/amp/auto_cast.py
python/paddle/amp/debugging.py
python/paddle/audio/backends/backend.py
python/paddle/audio/backends/init_backend.py
python/paddle/audio/backends/wave_backend.py
python/paddle/audio/datasets/dataset.py
python/paddle/audio/datasets/esc50.py
python/paddle/audio/datasets/tess.py
python/paddle/audio/functional/window.py
python/paddle/autograd/autograd.py
python/paddle/autograd/backward_mode.py
python/paddle/autograd/py_layer.py
python/paddle/base/dygraph/base.py
python/paddle/base/framework.py
python/paddle/batch.py
python/paddle/decomposition/recompute.py
python/paddle/distributed/auto_parallel/api.py
python/paddle/distributed/auto_parallel/interface.py
python/paddle/distributed/auto_tuner/recorder.py
python/paddle/distributed/auto_tuner/utils.py
python/paddle/distributed/checkpoint/load_state_dict.py
python/paddle/distributed/checkpoint/metadata.py
python/paddle/distributed/checkpoint/utils.py
python/paddle/distributed/fleet/meta_parallel/pipeline_parallel.py
python/paddle/distributed/parallel.py
python/paddle/distributed/passes/auto_parallel_gradient_merge.py
python/paddle/distributed/passes/auto_parallel_master_grad.py
python/paddle/distribution/bernoulli.py
python/paddle/distribution/beta.py
python/paddle/distribution/categorical.py
python/paddle/distribution/cauchy.py
python/paddle/distribution/dirichlet.py
python/paddle/distribution/distribution.py
python/paddle/distribution/exponential.py
python/paddle/distribution/gamma.py
python/paddle/distribution/geometric.py
python/paddle/distribution/gumbel.py
python/paddle/distribution/independent.py
python/paddle/distribution/laplace.py
python/paddle/distribution/lognormal.py
python/paddle/distribution/normal.py
python/paddle/distribution/transform.py
python/paddle/distribution/transformed_distribution.py
python/paddle/distribution/uniform.py
python/paddle/distribution/variable.py
python/paddle/fft.py
python/paddle/framework/random.py
python/paddle/hapi/callbacks.py
python/paddle/hapi/hub.py
python/paddle/hapi/model.py
python/paddle/hapi/model_summary.py
python/paddle/incubate/asp/asp.py
python/paddle/incubate/autograd/functional.py
python/paddle/incubate/autograd/primapi.py
python/paddle/incubate/autograd/primx.py
python/paddle/incubate/framework/random.py
python/paddle/incubate/nn/attn_bias.py
python/paddle/inference/wrapper.py
python/paddle/io/dataloader/batch_sampler.py
python/paddle/io/dataloader/dataset.py
python/paddle/io/dataloader/sampler.py
python/paddle/io/reader.py
python/paddle/jit/dy2static/ast_utils.py
python/paddle/jit/sot/opcode_translator/executor/dispatcher.py
python/paddle/jit/sot/opcode_translator/executor/executor_cache.py
python/paddle/jit/sot/opcode_translator/executor/function_graph.py
python/paddle/jit/sot/opcode_translator/executor/tracker.py
python/paddle/jit/sot/opcode_translator/executor/variables/iter.py
python/paddle/jit/utils.py
python/paddle/metric/metrics.py
python/paddle/nn/functional/conv.py
python/paddle/nn/functional/flash_attention.py
python/paddle/nn/functional/loss.py
python/paddle/nn/functional/norm.py
python/paddle/nn/functional/pooling.py
python/paddle/nn/initializer/assign.py
python/paddle/nn/layer/container.py
python/paddle/nn/layer/conv.py
python/paddle/nn/layer/layers.py
python/paddle/nn/layer/norm.py
python/paddle/nn/layer/pooling.py
python/paddle/nn/layer/transformer.py
python/paddle/nn/quant/format.py
python/paddle/nn/utils/clip_grad_norm_.py
python/paddle/nn/utils/clip_grad_value_.py
python/paddle/nn/utils/transform_parameters.py
python/paddle/optimizer/adadelta.py
python/paddle/optimizer/adagrad.py
python/paddle/optimizer/adam.py
python/paddle/optimizer/adamax.py
python/paddle/optimizer/adamw.py
python/paddle/optimizer/asgd.py
python/paddle/optimizer/lamb.py
🙋@Whsjrczr
python/paddle/optimizer/lbfgs.py
python/paddle/optimizer/lr.py
python/paddle/optimizer/momentum.py
python/paddle/optimizer/nadam.py
python/paddle/optimizer/optimizer.py
python/paddle/optimizer/radam.py
python/paddle/optimizer/rmsprop.py
python/paddle/optimizer/rprop.py
python/paddle/optimizer/sgd.py
python/paddle/profiler/profiler.py
python/paddle/quantization/config.py
python/paddle/reader/decorator.py
python/paddle/sparse/nn/functional/conv.py
python/paddle/sparse/nn/layer/conv.py
python/paddle/sparse/unary.py
python/paddle/tensor/array.py
python/paddle/tensor/creation.py
python/paddle/tensor/einsum.py
python/paddle/tensor/linalg.py
python/paddle/tensor/manipulation.py
python/paddle/tensor/math.py
python/paddle/tensor/stat.py
python/paddle/utils/cpp_extension/cpp_extension.py
python/paddle/vision/datasets/cifar.py
python/paddle/vision/datasets/flowers.py
python/paddle/vision/datasets/folder.py
python/paddle/vision/datasets/mnist.py
python/paddle/vision/datasets/voc2012.py
python/paddle/vision/models/_utils.py
python/paddle/vision/ops.py
✅@SigureMo
test/auto_parallel/hybrid_strategy/semi_auto_parallel_llama_model.py
test/deprecated/legacy_test/auto_parallel_op_test.py
test/dygraph_to_static/check_approval.py
test/dygraph_to_static/test_dynamic_shape_infermeta.py
test/dygraph_to_static/test_typehint.py
test/dygraph_to_static/test_typing.py
test/ipu/op_test_ipu.py
test/ir/inference/auto_scan_test.py
test/ir/inference/program_config.py
test/ir/inference/test_trt_convert_activation.py
test/ir/inference/test_trt_convert_affine_channel.py
test/ir/inference/test_trt_convert_anchor_generator.py
test/ir/inference/test_trt_convert_arg_max.py
test/ir/inference/test_trt_convert_arg_min.py
test/ir/inference/test_trt_convert_argsort.py
test/ir/inference/test_trt_convert_assign.py
test/ir/inference/test_trt_convert_batch_norm.py
test/ir/inference/test_trt_convert_bilinear_interp_v2.py
test/ir/inference/test_trt_convert_bitwise_and.py
test/ir/inference/test_trt_convert_bitwise_not.py
test/ir/inference/test_trt_convert_bitwise_or.py
test/ir/inference/test_trt_convert_bmm.py
test/ir/inference/test_trt_convert_cast.py
test/ir/inference/test_trt_convert_clip.py
test/ir/inference/test_trt_convert_compare_and_logical.py
test/ir/inference/test_trt_convert_concat.py
test/ir/inference/test_trt_convert_conv2d.py
test/ir/inference/test_trt_convert_conv2d_transpose.py
test/ir/inference/test_trt_convert_conv3d_transpose.py
test/ir/inference/test_trt_convert_cross_multihead_matmul.py
test/ir/inference/test_trt_convert_cumsum.py
test/ir/inference/test_trt_convert_deformable_conv.py
test/ir/inference/test_trt_convert_depthwise_conv2d.py
test/ir/inference/test_trt_convert_depthwise_conv2d_transpose.py
test/ir/inference/test_trt_convert_dropout.py
test/ir/inference/test_trt_convert_einsum.py
test/ir/inference/test_trt_convert_elementwise.py
test/ir/inference/test_trt_convert_elementwiseadd_transpose.py
test/ir/inference/test_trt_convert_emb_eltwise_layernorm.py
test/ir/inference/test_trt_convert_equal.py
test/ir/inference/test_trt_convert_expand_as_v2.py
test/ir/inference/test_trt_convert_expand_v2.py
test/ir/inference/test_trt_convert_fill_any_like.py
test/ir/inference/test_trt_convert_fill_constant.py
test/ir/inference/test_trt_convert_flash_multihead_matmul.py
test/ir/inference/test_trt_convert_flatten_contiguous_range.py
test/ir/inference/test_trt_convert_flip.py
test/ir/inference/test_trt_convert_fused_conv2d_add_act.py
test/ir/inference/test_trt_convert_fused_token_prune.py
test/ir/inference/test_trt_convert_gather.py
test/ir/inference/test_trt_convert_gather_nd.py
test/ir/inference/test_trt_convert_gelu.py
test/ir/inference/test_trt_convert_grid_sampler.py
test/ir/inference/test_trt_convert_group_norm.py
test/ir/inference/test_trt_convert_hard_sigmoid.py
test/ir/inference/test_trt_convert_hard_swish.py
test/ir/inference/test_trt_convert_index_select.py
test/ir/inference/test_trt_convert_instance_norm.py
test/ir/inference/test_trt_convert_inverse.py
test/ir/inference/test_trt_convert_layer_norm.py
test/ir/inference/test_trt_convert_leaky_relu.py
test/ir/inference/test_trt_convert_lookup_table.py
test/ir/inference/test_trt_convert_lookup_table_v2.py
test/ir/inference/test_trt_convert_matmul.py
test/ir/inference/test_trt_convert_matmul_v2.py
test/ir/inference/test_trt_convert_multiclass_nms.py
test/ir/inference/test_trt_convert_multiclass_nms3.py
test/ir/inference/test_trt_convert_multihead_matmul.py
test/ir/inference/test_trt_convert_multihead_matmul_roformer.py
test/ir/inference/test_trt_convert_nearest_interp.py
test/ir/inference/test_trt_convert_nearest_interp_v2.py
test/ir/inference/test_trt_convert_one_hot.py
test/ir/inference/test_trt_convert_p_norm.py
test/ir/inference/test_trt_convert_pad.py
test/ir/inference/test_trt_convert_pad3d.py
test/ir/inference/test_trt_convert_pool2d.py
test/ir/inference/test_trt_convert_preln_residual_bias.py
test/ir/inference/test_trt_convert_preln_residual_no_bias.py
test/ir/inference/test_trt_convert_prelu.py
test/ir/inference/test_trt_convert_qk_multihead_matmul.py
test/ir/inference/test_trt_convert_quantize_dequantize_linear.py
test/ir/inference/test_trt_convert_range.py
test/ir/inference/test_trt_convert_reduce.py
test/ir/inference/test_trt_convert_reshape.py
test/ir/inference/test_trt_convert_rnn.py
test/ir/inference/test_trt_convert_roi_align.py
test/ir/inference/test_trt_convert_roll.py
test/ir/inference/test_trt_convert_scale.py
test/ir/inference/test_trt_convert_scatter.py
test/ir/inference/test_trt_convert_scatter_nd_add.py
test/ir/inference/test_trt_convert_shape.py
test/ir/inference/test_trt_convert_share_data.py
test/ir/inference/test_trt_convert_shuffle_channel.py
test/ir/inference/test_trt_convert_size.py
test/ir/inference/test_trt_convert_slice.py
test/ir/inference/test_trt_convert_softmax.py
test/ir/inference/test_trt_convert_solve.py
test/ir/inference/test_trt_convert_split.py
test/ir/inference/test_trt_convert_square.py
test/ir/inference/test_trt_convert_squeeze2.py
test/ir/inference/test_trt_convert_stack.py
test/ir/inference/test_trt_convert_strided_slice.py
test/ir/inference/test_trt_convert_sum.py
test/ir/inference/test_trt_convert_swish.py
test/ir/inference/test_trt_convert_take_along_axis.py
test/ir/inference/test_trt_convert_temporal_shift.py
test/ir/inference/test_trt_convert_tile.py
test/ir/inference/test_trt_convert_top_k.py
test/ir/inference/test_trt_convert_top_k_v2.py
test/ir/inference/test_trt_convert_trans_layernorm.py
test/ir/inference/test_trt_convert_transpose.py
test/ir/inference/test_trt_convert_unary.py
test/ir/inference/test_trt_convert_unbind.py
test/ir/inference/test_trt_convert_unfold.py
test/ir/inference/test_trt_convert_unsqueeze2.py
test/ir/inference/test_trt_convert_where.py
test/ir/inference/test_trt_convert_yolo_box.py
test/ir/inference/test_trt_convert_yolo_box_head.py
test/ir/inference/test_trt_float64.py
test/ir/inference/test_trt_int64.py
test/ir/inference/test_trt_ops_fp32_mix_precision.py
test/ir/pir/cinn/llama_test_model.py
test/legacy_test/auto_parallel_op_test.py
test/legacy_test/test_gast_with_compatibility.py
test/legacy_test/test_memory_efficient_attention.py
test/legacy_test/utils.py
test/prim/model/bert.py
test/quantization/test_customized_quanter.py
test/sot/test_builtin_map.py
tools/cinn/gen_c++_tutorial.py
tools/sampcd_processor.py
任务认领方式
⭐️ 提交PR 模版 ⭐️:
或者多个任务:
Note
北航同学请注意在任务标题中添加
[BUAA]
,如:⭐️ 认领方式 ⭐️:
请大家以 comment 的形式认领任务,如:
Note
建议前期先只提 1 个 PR 熟悉流程,如果被 reviewer approve 了,那么后续可以每个 PR 修改 5-10 个文件,避免提交太多 PR, 以避免重复问题。
Warning
单个 PR 提交禁止修改超过 10 个文件, 否则会被 reviewer close。
提交 PR 模版
状态介绍:
✅:已经完全迁移,所有单测都OK!
🙋: 报名
🟢:审核完毕待合入,合入之后完成!
🔵:可认领!
🟡:当前阶段不需要人力继续跟进,下阶段推进
🚧:迁移中,单测还没有过,还没有审核完。
大致正常流程为:
🔵 -> 🙋 -> 🚧 -> 🟢 -> ✅
异常流程为:
🔵 -> 🙋 -> 🚧 -> 🟡
看板信息
拓展延伸
感兴趣的同学可以了解下 PEP 649 和 PEP 749,看看未来 Python(3.14+)又是使用了什么方案来替代 PEP 563 的~
Footnotes
https://devguide.python.org/versions/ ↩
The text was updated successfully, but these errors were encountered: