[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"similar-ilkarman--DeepLearningFrameworks":3,"tool-ilkarman--DeepLearningFrameworks":64},[4,17,27,35,43,56],{"id":5,"name":6,"github_repo":7,"description_zh":8,"stars":9,"difficulty_score":10,"last_commit_at":11,"category_tags":12,"status":16},3808,"stable-diffusion-webui","AUTOMATIC1111\u002Fstable-diffusion-webui","stable-diffusion-webui 是一个基于 Gradio 构建的网页版操作界面，旨在让用户能够轻松地在本地运行和使用强大的 Stable Diffusion 图像生成模型。它解决了原始模型依赖命令行、操作门槛高且功能分散的痛点，将复杂的 AI 绘图流程整合进一个直观易用的图形化平台。\n\n无论是希望快速上手的普通创作者、需要精细控制画面细节的设计师，还是想要深入探索模型潜力的开发者与研究人员，都能从中获益。其核心亮点在于极高的功能丰富度：不仅支持文生图、图生图、局部重绘（Inpainting）和外绘（Outpainting）等基础模式，还独创了注意力机制调整、提示词矩阵、负向提示词以及“高清修复”等高级功能。此外，它内置了 GFPGAN 和 CodeFormer 等人脸修复工具，支持多种神经网络放大算法，并允许用户通过插件系统无限扩展能力。即使是显存有限的设备，stable-diffusion-webui 也提供了相应的优化选项，让高质量的 AI 艺术创作变得触手可及。",162132,3,"2026-04-05T11:01:52",[13,14,15],"开发框架","图像","Agent","ready",{"id":18,"name":19,"github_repo":20,"description_zh":21,"stars":22,"difficulty_score":23,"last_commit_at":24,"category_tags":25,"status":16},1381,"everything-claude-code","affaan-m\u002Feverything-claude-code","everything-claude-code 是一套专为 AI 编程助手（如 Claude Code、Codex、Cursor 等）打造的高性能优化系统。它不仅仅是一组配置文件，而是一个经过长期实战打磨的完整框架，旨在解决 AI 代理在实际开发中面临的效率低下、记忆丢失、安全隐患及缺乏持续学习能力等核心痛点。\n\n通过引入技能模块化、直觉增强、记忆持久化机制以及内置的安全扫描功能，everything-claude-code 能显著提升 AI 在复杂任务中的表现，帮助开发者构建更稳定、更智能的生产级 AI 代理。其独特的“研究优先”开发理念和针对 Token 消耗的优化策略，使得模型响应更快、成本更低，同时有效防御潜在的攻击向量。\n\n这套工具特别适合软件开发者、AI 研究人员以及希望深度定制 AI 工作流的技术团队使用。无论您是在构建大型代码库，还是需要 AI 协助进行安全审计与自动化测试，everything-claude-code 都能提供强大的底层支持。作为一个曾荣获 Anthropic 黑客大奖的开源项目，它融合了多语言支持与丰富的实战钩子（hooks），让 AI 真正成长为懂上",138956,2,"2026-04-05T11:33:21",[13,15,26],"语言模型",{"id":28,"name":29,"github_repo":30,"description_zh":31,"stars":32,"difficulty_score":23,"last_commit_at":33,"category_tags":34,"status":16},2271,"ComfyUI","Comfy-Org\u002FComfyUI","ComfyUI 是一款功能强大且高度模块化的视觉 AI 引擎，专为设计和执行复杂的 Stable Diffusion 图像生成流程而打造。它摒弃了传统的代码编写模式，采用直观的节点式流程图界面，让用户通过连接不同的功能模块即可构建个性化的生成管线。\n\n这一设计巧妙解决了高级 AI 绘图工作流配置复杂、灵活性不足的痛点。用户无需具备编程背景，也能自由组合模型、调整参数并实时预览效果，轻松实现从基础文生图到多步骤高清修复等各类复杂任务。ComfyUI 拥有极佳的兼容性，不仅支持 Windows、macOS 和 Linux 全平台，还广泛适配 NVIDIA、AMD、Intel 及苹果 Silicon 等多种硬件架构，并率先支持 SDXL、Flux、SD3 等前沿模型。\n\n无论是希望深入探索算法潜力的研究人员和开发者，还是追求极致创作自由度的设计师与资深 AI 绘画爱好者，ComfyUI 都能提供强大的支持。其独特的模块化架构允许社区不断扩展新功能，使其成为当前最灵活、生态最丰富的开源扩散模型工具之一，帮助用户将创意高效转化为现实。",107662,"2026-04-03T11:11:01",[13,14,15],{"id":36,"name":37,"github_repo":38,"description_zh":39,"stars":40,"difficulty_score":23,"last_commit_at":41,"category_tags":42,"status":16},3704,"NextChat","ChatGPTNextWeb\u002FNextChat","NextChat 是一款轻量且极速的 AI 助手，旨在为用户提供流畅、跨平台的大模型交互体验。它完美解决了用户在多设备间切换时难以保持对话连续性，以及面对众多 AI 模型不知如何统一管理的痛点。无论是日常办公、学习辅助还是创意激发，NextChat 都能让用户随时随地通过网页、iOS、Android、Windows、MacOS 或 Linux 端无缝接入智能服务。\n\n这款工具非常适合普通用户、学生、职场人士以及需要私有化部署的企业团队使用。对于开发者而言，它也提供了便捷的自托管方案，支持一键部署到 Vercel 或 Zeabur 等平台。\n\nNextChat 的核心亮点在于其广泛的模型兼容性，原生支持 Claude、DeepSeek、GPT-4 及 Gemini Pro 等主流大模型，让用户在一个界面即可自由切换不同 AI 能力。此外，它还率先支持 MCP（Model Context Protocol）协议，增强了上下文处理能力。针对企业用户，NextChat 提供专业版解决方案，具备品牌定制、细粒度权限控制、内部知识库整合及安全审计等功能，满足公司对数据隐私和个性化管理的高标准要求。",87618,"2026-04-05T07:20:52",[13,26],{"id":44,"name":45,"github_repo":46,"description_zh":47,"stars":48,"difficulty_score":23,"last_commit_at":49,"category_tags":50,"status":16},2268,"ML-For-Beginners","microsoft\u002FML-For-Beginners","ML-For-Beginners 是由微软推出的一套系统化机器学习入门课程，旨在帮助零基础用户轻松掌握经典机器学习知识。这套课程将学习路径规划为 12 周，包含 26 节精炼课程和 52 道配套测验，内容涵盖从基础概念到实际应用的完整流程，有效解决了初学者面对庞大知识体系时无从下手、缺乏结构化指导的痛点。\n\n无论是希望转型的开发者、需要补充算法背景的研究人员，还是对人工智能充满好奇的普通爱好者，都能从中受益。课程不仅提供了清晰的理论讲解，还强调动手实践，让用户在循序渐进中建立扎实的技能基础。其独特的亮点在于强大的多语言支持，通过自动化机制提供了包括简体中文在内的 50 多种语言版本，极大地降低了全球不同背景用户的学习门槛。此外，项目采用开源协作模式，社区活跃且内容持续更新，确保学习者能获取前沿且准确的技术资讯。如果你正寻找一条清晰、友好且专业的机器学习入门之路，ML-For-Beginners 将是理想的起点。",84991,"2026-04-05T10:45:23",[14,51,52,53,15,54,26,13,55],"数据工具","视频","插件","其他","音频",{"id":57,"name":58,"github_repo":59,"description_zh":60,"stars":61,"difficulty_score":10,"last_commit_at":62,"category_tags":63,"status":16},3128,"ragflow","infiniflow\u002Fragflow","RAGFlow 是一款领先的开源检索增强生成（RAG）引擎，旨在为大语言模型构建更精准、可靠的上下文层。它巧妙地将前沿的 RAG 技术与智能体（Agent）能力相结合，不仅支持从各类文档中高效提取知识，还能让模型基于这些知识进行逻辑推理和任务执行。\n\n在大模型应用中，幻觉问题和知识滞后是常见痛点。RAGFlow 通过深度解析复杂文档结构（如表格、图表及混合排版），显著提升了信息检索的准确度，从而有效减少模型“胡编乱造”的现象，确保回答既有据可依又具备时效性。其内置的智能体机制更进一步，使系统不仅能回答问题，还能自主规划步骤解决复杂问题。\n\n这款工具特别适合开发者、企业技术团队以及 AI 研究人员使用。无论是希望快速搭建私有知识库问答系统，还是致力于探索大模型在垂直领域落地的创新者，都能从中受益。RAGFlow 提供了可视化的工作流编排界面和灵活的 API 接口，既降低了非算法背景用户的上手门槛，也满足了专业开发者对系统深度定制的需求。作为基于 Apache 2.0 协议开源的项目，它正成为连接通用大模型与行业专有知识之间的重要桥梁。",77062,"2026-04-04T04:44:48",[15,14,13,26,54],{"id":65,"github_repo":66,"name":67,"description_en":68,"description_zh":69,"ai_summary_zh":69,"readme_en":70,"readme_zh":71,"quickstart_zh":72,"use_case_zh":73,"hero_image_url":74,"owner_login":75,"owner_name":76,"owner_avatar_url":77,"owner_bio":78,"owner_company":79,"owner_location":80,"owner_email":78,"owner_twitter":78,"owner_website":81,"owner_url":82,"languages":83,"stars":96,"forks":97,"last_commit_at":98,"license":99,"difficulty_score":23,"env_os":100,"env_gpu":101,"env_ram":102,"env_deps":103,"category_tags":116,"github_topics":78,"view_count":23,"oss_zip_url":78,"oss_zip_packed_at":78,"status":16,"created_at":117,"updated_at":118,"faqs":119,"releases":150},1359,"ilkarman\u002FDeepLearningFrameworks","DeepLearningFrameworks","Demo of running NNs across different frameworks","DeepLearningFrameworks 是一份“深度学习框架对照表”，用同一份 CIFAR-10 图像识别任务和 ChestXRay DenseNet 训练任务，把 Caffe2、PyTorch、TensorFlow、MXNet、CNTK、Keras、Chainer、Julia-Knet、R-Keras 等主流框架放在同一起跑线上，给出可复现的训练时间、显存占用和准确率。它解决了“换框架就要重写代码、性能差异心里没底”的痛点，让数据科学家能把已有经验平滑迁移到新框架，也能快速验证自己的 GPU\u002F驱动\u002F精度设置是否达到官方预期。  \n项目运行在 Azure 深度学习虚拟机，所有 Notebook 开箱即用，既支持单 GPU 也支持多卡并行，并优先采用各框架最新、最高层 API，保证代码简洁、性能最优。  \n适合正在选型或迁移的研究人员、算法工程师，以及想横向对比框架性能的技术决策者。","# Deep Learning Framework Examples\n   \n\u003Cp align=\"center\">\n\u003Cimg src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Filkarman_DeepLearningFrameworks_readme_87876be4d8a6.png\" alt=\"logo\" width=\"50%\"\u002F>\n\u003C\u002Fp>\n\n\n**For more details check out our [blog-post](https:\u002F\u002Fblogs.technet.microsoft.com\u002Fmachinelearning\u002F2018\u002F03\u002F14\u002Fcomparing-deep-learning-frameworks-a-rosetta-stone-approach\u002F)**\n\n## Goal\n\n1. Create a Rosetta Stone of deep-learning frameworks to allow data-scientists to easily leverage their expertise from one framework to another\n2. Optimised GPU code with using the most up-to-date highest-level APIs.\n3. Common setup for comparisons across GPUs (potentially CUDA versions and precision)\n4. Common setup for comparisons across languages (Python, Julia, R)\n5. Possibility to verify expected performance of own installation\n4. Collaboration between different open-source communities\n\nThe notebooks are executed on an Azure [Deep Learning Virtual Machine](https:\u002F\u002Fazuremarketplace.microsoft.com\u002Fen-us\u002Fmarketplace\u002Fapps\u002Fmicrosoft-ads.dsvm-deep-learning). \n\n*Accuracies (and other metrics) are reported in notebooks*\n\n## Results\n\n### 1. Training Time(s): CNN (VGG-style, 32bit) on CIFAR-10 - Image Recognition\n\n| DL Library                                            | K80\u002FCUDA 8\u002FCuDNN 6 | P100\u002FCUDA 8\u002FCuDNN 6 |\n| ----------------------------------------------------- | :----------------: | :-----------------: |\n| [Caffe2](notebooks\u002FCaffe2_CNN.ipynb)                  |        148         |         54          |\n| [Chainer](notebooks\u002FChainer_CNN.ipynb)                |        162         |         69          |\n| [CNTK](notebooks\u002FCNTK_CNN.ipynb)                      |        163         |         53          |\n| [MXNet(Gluon)](notebooks\u002FGluon_CNN.ipynb)             |        152         |         57          |\n| [Keras(CNTK)](notebooks\u002FKeras_CNTK_CNN.ipynb)         |        194         |         76          |\n| [Keras(TF)](notebooks\u002FKeras_TF_CNN.ipynb)             |        241         |         76          |\n| [Keras(Theano)](notebooks\u002FKeras_Theano_CNN.ipynb)     |        269         |         93          |\n| [Tensorflow](notebooks\u002FTensorflow_CNN.ipynb)          |        173         |         57          |\n| [Lasagne(Theano)](notebooks\u002FTheano_Lasagne_CNN.ipynb) |        253         |         65          |\n| [MXNet(Module API)](notebooks\u002FMXNet_CNN.ipynb)        |        145         |         52          |\n| [PyTorch](notebooks\u002FPyTorch_CNN.ipynb)                |        169         |         51          |\n| [Julia - Knet](notebooks\u002FKnet_CNN.ipynb)              |        159         |         ??          |\n| [R - Keras(TF)](notebooks\u002FKerasR_TF_CNN.ipynb)        |        205         |         72          |\n\n\n*Note: It is recommended to use higher level APIs where possible; see these notebooks for examples with [Tensorflow](notebooks\u002FTensorflow_CNN_highAPI.ipynb), [MXNet](notebooks\u002FMXNet_CNN_highAPI.ipynb) and [CNTK](notebooks\u002FCNTK_CNN_highAPI.ipynb). They are not linked in the table to keep the common-structure-for-all approach*\n\nInput for this model is the standard [CIFAR-10 dataset](http:\u002F\u002Fwww.cs.toronto.edu\u002F~kriz\u002Fcifar.html) containing 50k training images and 10k test images, uniformly split across 10 classes. Each 32 by 32 image is supplied as a tensor of shape (3, 32, 32) with pixel intensity re-scaled from 0-255 to 0-1. \n\n### 2. Training Time: DenseNet-121 on ChestXRay - Image Recognition (Multi-GPU)\n\n**Train+Val w\u002F data-loader + data-augmentation on real-data on SSD**\n\n| DL Library                                        | 1xV100\u002FCUDA 9\u002FCuDNN 7 | 4xV100\u002FCUDA 9\u002FCuDNN 7 |\n| -----------------------------------------------   | :------------------:  | :------------------:  |\n| [Pytorch](notebooks\u002FPyTorch_MultiGPU.ipynb)       | 27min                 | 10min                 |\n| [Keras(TF)](notebooks\u002FKeras_TF_MultiGPU.ipynb)    | 38min                 | 18min                 |\n| [Tensorflow](notebooks\u002FTensorflow_MultiGPU.ipynb) | 33min                 | 22min                 |\n| [Chainer](notebooks\u002FChainer_MultiGPU.ipynb)       | 29min                 | 8min                  |\n| [MXNet(Gluon)](notebooks\u002FGluon_MultiGPU.ipynb)    | 29min                 | 10min                 |\n\n**Train w\u002F synthetic-data in RAM**\n\n| DL Library                                        | 1xV100\u002FCUDA 9\u002FCuDNN 7 | 4xV100\u002FCUDA 9\u002FCuDNN 7 |\n| -----------------------------------------------   | :------------------:  | :------------------:  |\n| [Pytorch](notebooks\u002FPyTorch_MultiGPU.ipynb)       | 25min                 | 8min                  |\n| [Keras(TF)](notebooks\u002FKeras_TF_MultiGPU.ipynb)    | 36min                 | 15min                 |\n| [Tensorflow](notebooks\u002FTensorflow_MultiGPU.ipynb) | 25min                 | 14min                 |\n| [Chainer](notebooks\u002FChainer_MultiGPU.ipynb)       | 27min                 | 7min                  |\n| [MXNet(Gluon)](notebooks\u002FGluon_MultiGPU.ipynb)    | 28min                 | 8min                  |\n\nNotes:\n\n1. Chainer suffered an AUC drop relative to all other frameworks when going from single to multi-GPU\n\nInput for this model is 112,120 PNGs of chest X-rays resized to (264, 264). **Note for the notebook to automatically download the data you must install [Azcopy](https:\u002F\u002Fdocs.microsoft.com\u002Fen-us\u002Fazure\u002Fstorage\u002Fcommon\u002Fstorage-use-azcopy-linux#download-and-install-azcopy) and increase the size of your OS-Disk in Azure Portal so that you have at-least 45GB of free-space (the Chest X-ray data is large!). The notebooks may take more than 10 minutes to first download the data.** These notebooks train DenseNet-121 and use native data-loaders to pre-process the data perform some augmentations (random horizontal flip and random crop to 224px).\n\n### 3. Avg Time(s) for 1000 images: ResNet-50 - Feature Extraction\n\n| DL Library                                          | K80\u002FCUDA 8\u002FCuDNN 6 | P100\u002FCUDA 8\u002FCuDNN 6 |\n| --------------------------------------------------- | :----------------: | :-----------------: |\n| [Caffe2](notebooks\u002FCaffe2_Inference.ipynb)          | 14.1               | 7.9                 |\n| [Chainer](notebooks\u002FChainer_Inference.ipynb)        | 9.3                | 2.7                 |\n| [CNTK](notebooks\u002FCNTK_Inference.ipynb)              | 8.5                | 1.6                 |\n| [MXNet(Gluon)](notebooks\u002FGluon_Inference.ipynb)     |                    | 1.7                 |\n| [Keras(CNTK)](notebooks\u002FKeras_CNTK_Inference.ipynb) | 21.7               | 5.9                 |\n| [Keras(TF)](notebooks\u002FKeras_TF_Inference.ipynb)     | 10.2               | 2.9                 |\n| [Tensorflow](notebooks\u002FTensorflow_Inference.ipynb)  | 6.5                | 1.8                 |\n| [MXNet(Module API)](notebooks\u002FMXNet_Inference.ipynb)| 7.7                | 1.6                 |\n| [PyTorch](notebooks\u002FPyTorch_Inference.ipynb)        | 7.7                | 1.9                 |\n| [Julia - Knet](notebooks\u002FKnet_Inference.ipynb)      | 6.3                | ???                 |\n| [R - MXNet](notebooks\u002F.ipynb)                       | ???                | ???                 |\n| [R - Keras(TF)](notebooks\u002FKerasR_TF_Inference.ipynb)| 17                 | 7.4                 |\n\n\nA pre-trained ResNet50 model is loaded and chopped just after the avg_pooling at the end (7, 7), which outputs a 2048D dimensional vector. This can be plugged into a softmax layer or another classifier such as a boosted tree to perform transfer learning. Allowing for a warm start; this forward-only pass to the avg_pool layer is timed. *Note: batch-size remains constant, however filling the RAM on a GPU would produce further performance boosts (greater for GPUs with more RAM).*\n\n### 4. Training Time(s): RNN (GRU) on IMDB - Sentiment Analysis\n\n| DL Library                               | K80\u002FCUDA 8\u002FCuDNN 6 | P100\u002FCUDA 8\u002FCuDNN 6 | Using CuDNN? |\n| ---------------------------------------- | :----------------: | :----------------:  | :----------: |\n| [CNTK](notebooks\u002FCNTK_RNN.ipynb)                   | 32                 | 15                  | Yes          |\n| [Keras(CNTK)](notebooks\u002FKeras_CNTK_RNN.ipynb)      | 86                 | 53                  | No           |\n| [Keras(TF)](notebooks\u002FKeras_TF_RNN.ipynb)          | 35                 | 26                  | Yes          |\n| [MXNet(Module API)](notebooks\u002FMXNet_RNN.ipynb)     | 29                 | 24                  | Yes          |\n| [MXNet(Gluon API)](notebooks\u002FGluon_RNN.ipynb)      | TBA                | TBA                 | Yes          |\n| [Pytorch](notebooks\u002FPyTorch_RNN.ipynb)             | 31                 | 16                  | Yes          |\n| [Tensorflow](notebooks\u002FTensorflow_RNN.ipynb)       | 30                 | 22                  | Yes          |\n| [Julia - Knet](notebooks\u002FKnet_RNN.ipynb)           | 29                 | ??                  | Yes          |\n| [R - MXNet](notebooks\u002F.ipynb)                      | ??                 | ??                  | ???          |\n| [R - Keras(TF)](notebooks\u002FKerasR_TF_RNN.ipynb)     | 35                 | 25                  | Yes          |\n\n\nInput for this model is the standard [IMDB movie review dataset](http:\u002F\u002Fai.stanford.edu\u002F~amaas\u002Fdata\u002Fsentiment\u002F) containing 25k training reviews and 25k test reviews, uniformly split across 2 classes (positive\u002Fnegative). Processing follows [Keras](https:\u002F\u002Fgithub.com\u002Ffchollet\u002Fkeras\u002Fblob\u002Fmaster\u002Fkeras\u002Fdatasets\u002Fimdb.py) approach where start-character is set as 1, out-of-vocab (vocab size of 30k is used) represented as 2 and thus word-index starts from 3. Zero-padded \u002F truncated to fixed axis of 150 words per review.\n\nWhere possible we try to use the cudnn-optimised RNN (noted by the CUDNN=True switch), since we have a vanilla RNN that can be easily reduced to the CuDNN level. For example with CNTK we use optimized_rnnstack instead of Recurrence(LSTM()). This is much faster but less flexible and, for example, with CNTK we can no longer use more complicated variants like Layer Normalisation, etc. It appears in PyTorch this is enabled by default. For MXNet I could not find this and instead use the slightly slower Fused RNN. Keras has just very recently received [cudnn support](https:\u002F\u002Ftwitter.com\u002Ffchollet\u002Fstatus\u002F918170264608817152), however only for the Tensorflow backend (not CNTK). Tensorflow has many RNN variants (including their own custom kernel) and there is a nice benchmark [here](http:\u002F\u002Freturnn.readthedocs.io\u002Fen\u002Flatest\u002Ftf_lstm_benchmark.html), I will try to update the example to use CudnnLSTM instead of the current method.\n\n*Note: CNTK  supports [dynamic axes](https:\u002F\u002Fcntk.ai\u002Fpythondocs\u002Fsequence.html) which means we don't need to pad the input to 150 words and can consume as-is, however since I could not find a way to do this with other frameworks I have fallen back to padding - which is a bit unfair on CNTK and understates its capabilities*\n\nThe classification model creates an embedding matrix of size (150x125) and then applies 100 gated recurrent units and takes as output the final output (not sequence of outputs and not hidden state). Any suggestions on alterations to this are welcome.\n\n## Lessons Learned\n\n#### CNN\n\nThe below offers some insights we gained after trying to match test-accuracy across frameworks and from all the GitHub issues\u002FPRs raised.\n\n1. The above examples (except for Keras), for ease of comparison, try to use the same level of API and so all use the same generator-function. For [MXNet](notebooks\u002FMXNet_CNN_highAPI.ipynb), [Tensorflow](notebooks\u002FTensorflow_CNN_highAPI.ipynb), and [CNTK](notebooks\u002FCNTK_CNN_highAPI.ipynb) I have experimented with a higher-level API, where I use the framework's training generator function. The speed improvement is negligible in this example because the whole dataset is loaded as NumPy array in RAM and the only processing done each epoch is a shuffle. I suspect the framework's generators perform the shuffle asynchronously. Curiously, it seems that the frameworks shuffle on a batch-level, rather than on an observation level, and thus ever so slightly decreases the test-accuracy (at least after 10 epochs). For scenarios where we have IO activity and perhaps pre-processing and data-augmentation on the fly, custom generators would have a much bigger impact on performance.\n\n2. Running on CuDNN we want to use [NCHW] instead of channels-last. Keras finally supports this for Tensorflow (previously it had NHWC hard-coded and would auto-reshape after every batch)\n\n3. Enabling CuDNN's auto-tune\u002Fexhaustive search parameter (which selects the most efficient CNN algorithm for images of fixed-size) produced a huge performance boost on the K80 many months ago. However, now most frameworks have automatically integrated this.\n\n4. Some frameworks required a boolean supplied to the dropout-layer indicating whether we were training or not (this had a huge impact on test-accuracy, 72 vs 77%). Dropout should not be applied to test in this case.\n\n5. TF_ENABLE_WINOGRAD_NONFUSED no longer speeds up TensorFlow's CNN and actually makes it slower\n\n6. Softmax is usually bundled with cross_entropy_loss() for most functions and it's worth checking if you need an activation on your final fully-connected layer to save time applying it twice\n\n7. Kernel initializer for different frameworks can vary (I've found this to have +\u002F- 1% effect on accuracy) and I try to specify xavier\u002Fglorot uniform whenever possible\u002Fnot too verbose\n\n8. Type of momentum implemented for SGD-momentum; I had to turn off unit_gain (which was on by default in CNTK) to match other frameworks' implementations\n\n9. Caffe2 has an extra optimisation for the first layer of a network (no_gradient_to_input=1) that produces a small speed-boost by not computing gradients for input. It's possible that Tensorflow and MXNet already enable this by default. Computing this gradient could be useful for research purposes and for networks like deep-dream\n\n10. Applying the ReLU activation after max-pooling (instead of before) means you perform a calculation after dimensionality-reduction and thus shave off a few seconds. This helped reduce MXNet time by 3 seconds\n\n11. Some **further checks** which may be useful: \n   * specifying kernel as (3) becomes a symmetric tuple (3, 3) or 1D convolution (3, 1)?\n   * strides (for max-pooling) are (1, 1) by default or equal to kernel (Keras does this)? \n   * default padding is usually off (0, 0)\u002Fvalid but useful to check it's not on\u002F'same'\n   * is the default activation on a convolutional layer 'None' or 'ReLu' (Lasagne)\n   * the bias initializer may vary (sometimes no bias is included)\n   * gradient clipping and treatment of inifinty\u002FNaNs may differ across frameworks\n   * some frameworks support sparse labels instead of one-hot (which I use if available, e.g. Tensorflow has f.nn.sparse_softmax_cross_entropy_with_logits)\n   * data-type assumptions may be different - I try to use float32 and int32 for X and y but, for example, torch needs double for y (to be coerced into torch.LongTensor(y).cuda)\n   * if the framework has a slightly lower-level API make sure during testing you don't compute the gradient by setting something like training=False\n\n12. Installing Caffe2 for python 3.5 proved a bit difficult so I wanted to share the process:\n   ```\n   # build as root\n   sudo -s\n   cd \u002Fopt\u002Fcaffe2\n   make clean\n   git pull\n   git checkout v0.8.1\n   git submodule update\n   export CPLUS_INCLUDE_PATH=\u002Fanaconda\u002Fenvs\u002Fpy35\u002Finclude\u002Fpython3.5m\n   mkdir build\n   cd build\n   echo $PATH\n   # CONFIRM that Anaconda is not in the path\n   cmake .. -DBLAS=MKL -DPYTHON_INCLUDE_DIR=\u002Fanaconda\u002Fenvs\u002Fpy35\u002Finclude\u002Fpython3.5m -DPYTHON_LIBRARY=\u002Fanaconda\u002Fenvs\u002Fpy35\u002Flib\u002Flibpython3.5m.so -DPYTHON_EXECUTABLE=\u002Fanaconda\u002Fenvs\u002Fpy35\u002Fbin\u002Fpython\n   make -j$(nproc)\n   make install\n   ```\n\n13. When using MXNet, you should avoid assigning outputs or data to numpy np.array in your training loop. This causes the data to be copied from the GPU to the CPU. You should use mx.nd.array instead, allocated in the right context at the beginning. This can dramatically increase performance.\n\n14. When using MXNet, operations are allocated on the queue of the back-end engine and parallelized, try to avoid any blocking operations in your training loop. You can add a nd.waitall(), which will force waiting for all operations to complete at the end of each epoch to avoid filling up your memory.\n\n15. With MXNet\u002FGluon, calling `.hybridize()` on your network will cache the computation graph and you will get performance gains. However that means that you won't be able to step through every calculations anymore. Use it once you are done debugging your network.\n\n#### RNN\n\n1. There are multiple RNN implementations\u002Fkernels available for most frameworks (for example [Tensorflow](http:\u002F\u002Freturnn.readthedocs.io\u002Fen\u002Flatest\u002Ftf_lstm_benchmark.html)); once reduced down to the cudnnLSTM\u002FGRU level the execution is the fastest, however this implementation is less flexible (e.g. maybe you want layer normalisation) and may become problematic if inference is run on the CPU at a later stage. At the cudDNN level most of the frameworks' runtimes are very similar. [This](https:\u002F\u002Fdevblogs.nvidia.com\u002Fparallelforall\u002Foptimizing-recurrent-neural-networks-cudnn-5\u002F) Nvidia blog-post goes through several interesting cuDNN optimisations for recurrent neural nets e.g. fusing - \"combining the computation of many small matrices into that of larger ones and streaming the computation whenever possible, the ratio of computation to memory I\u002FO can be increased, which results in better performance on GPU\".\n\n2. It seems that the fastest data-shape for RNNs is TNC - implementing this in [MXNet](notebooks\u002FMXNet_RNN_TNC.ipynb) only gave an improvement of 0.5s so I have chosen to use the sligthly slower shape to remain consistent with other frameworks and to keep the code less complicated\n","# 深度学习框架示例\n\n\u003Cp align=\"center\">\n\u003Cimg src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Filkarman_DeepLearningFrameworks_readme_87876be4d8a6.png\" alt=\"logo\" width=\"50%\"\u002F>\n\u003C\u002Fp>\n\n\n**如需了解更多详情，请查看我们的[博客文章](https:\u002F\u002Fblogs.technet.microsoft.com\u002Fmachinelearning\u002F2018\u002F03\u002F14\u002Fcomparing-deep-learning-frameworks-a-rosetta-stone-approach\u002F)**\n\n## 目标\n\n1. 创建一套深度学习框架的“罗塞塔石碑”系统，使数据科学家能够轻松地将自身在某一框架中的专业经验迁移到其他框架中。\n2. 优化 GPU 代码，充分利用最新、最顶级的 API。\n3. 提供通用的设置方案，支持跨 GPU 进行对比测试（可能涵盖 CUDA 版本及精度配置）。\n4. 提供通用的设置方案，支持跨多种语言进行对比测试（Python、Julia、R）。\n5. 允许用户验证自己安装环境的预期性能表现。\n6. 促进不同开源社区之间的协作。\n\n这些笔记本是在 Azure [深度学习虚拟机](https:\u002F\u002Fazuremarketplace.microsoft.com\u002Fen-us\u002Fmarketplace\u002Fapps\u002Fmicrosoft-ads.dsvm-deep-learning) 上运行的。\n\n*笔记中会报告准确率（以及其他相关指标）*\n\n## 结果\n\n### 1. 训练时间：CNN（VGG 风格，32 位）在 CIFAR-10 图像识别任务上的训练时间\n\n| DL 库                                            | K80\u002FCUDA 8\u002FCuDNN 6 | P100\u002FCUDA 8\u002FCuDNN 6 |\n| ----------------------------------------------------- | :----------------: | :-----------------: |\n| [Caffe2](notebooks\u002FCaffe2_CNN.ipynb)                  |        148         |         54          |\n| [Chainer](notebooks\u002FChainer_CNN.ipynb)                |        162         |         69          |\n| [CNTK](notebooks\u002FCNTK_CNN.ipynb)                      |        163         |         53          |\n| [MXNet(Gluon)](notebooks\u002FGluon_CNN.ipynb)             |        152         |         57          |\n| [Keras(CNTK)](notebooks\u002FKeras_CNTK_CNN.ipynb)         |        194         |         76          |\n| [Keras(TF)](notebooks\u002FKeras_TF_CNN.ipynb)             |        241         |         76          |\n| [Keras(Theano)](notebooks\u002FKeras_Theano_CNN.ipynb)     |        269         |         93          |\n| [Tensorflow](notebooks\u002FTensorflow_CNN.ipynb)          |        173         |         57          |\n| [Lasagne(Theano)](notebooks\u002FTheano_Lasagne_CNN.ipynb) |        253         |         65          |\n| [MXNet(Module API)](notebooks\u002FMXNet_CNN.ipynb)        |        145         |         52          |\n| [PyTorch](notebooks\u002FPyTorch_CNN.ipynb)                |        169         |         51          |\n| [Julia - Knet](notebooks\u002FKnet_CNN.ipynb)              |        159         |         ??          |\n| [R - Keras(TF)](notebooks\u002FKerasR_TF_CNN.ipynb)        |        205         |         72          |\n\n\n*注意：建议尽可能使用更高层次的 API；有关示例，请参阅这些笔记本，例如 [Tensorflow](notebooks\u002FTensorflow_CNN_highAPI.ipynb)、[MXNet](notebooks\u002FMXNet_CNN_highAPI.ipynb) 和 [CNTK](notebooks\u002FCNTK_CNN_highAPI.ipynb)。为保持统一的结构，这些工具并未在表格中直接链接。*\n\n该模型的输入数据为标准的 [CIFAR-10 数据集](http:\u002F\u002Fwww.cs.toronto.edu\u002F~kriz\u002Fcifar.html)，包含 5 万张训练图像和 1 万张测试图像，均匀划分为 10 个类别。每张 32×32 的图像被映射为一个形状为 (3, 32, 32) 的张量，其像素强度从 0–255 被缩放到 0–1。\n\n### 2. 训练时间：DenseNet-121 在 ChestXRay 图像识别任务上（多 GPU 环境）\n\n**使用数据加载器与数据增强，并在 SSD 硬件上进行训练与验证**\n\n| DL 库                                        | 1xV100\u002FCUDA 9\u002FCuDNN 7 | 4xV100\u002FCUDA 9\u002FCuDNN 7 |\n| -----------------------------------------------   | :------------------:  | :------------------:  |\n| [Pytorch](notebooks\u002FPyTorch_MultiGPU.ipynb)       | 27 分钟                 | 10 分钟                 |\n| [Keras(TF)](notebooks\u002FKeras_TF_MultiGPU.ipynb)    | 38 分钟                 | 18 分钟                 |\n| [Tensorflow](notebooks\u002FTensorflow_MultiGPU.ipynb) | 33 分钟                 | 22 分钟                 |\n| [Chainer](notebooks\u002FChainer_MultiGPU.ipynb)       | 29 分钟                 | 8 分钟                  |\n| [MXNet(Gluon)](notebooks\u002FGluon_MultiGPU.ipynb)    | 29 分钟                 | 10 分钟                 |\n\n**使用内存中的合成数据进行训练**\n\n| DL 库                                        | 1xV100\u002FCUDA 9\u002FCuDNN 7 | 4xV100\u002FCUDA 9\u002FCuDNN 7 |\n| -----------------------------------------------   | :------------------:  | :------------------:  |\n| [Pytorch](notebooks\u002FPyTorch_MultiGPU.ipynb)       | 25 分钟                 | 8 分钟                  |\n| [Keras(TF)](notebooks\u002FKeras_TF_MultiGPU.ipynb)    | 36 分钟                 | 15 分钟                 |\n| [Tensorflow](notebooks\u002FTensorflow_MultiGPU.ipynb) | 25 分钟                 | 14 分钟                 |\n| [Chainer](notebooks\u002FChainer_MultiGPU.ipynb)       | 27 分钟                 | 7 分钟                  |\n| [MXNet(Gluon)](notebooks\u002FGluon_MultiGPU.ipynb)    | 28 分钟                 | 8 分钟                  |\n\n注释：\n1. 与其他所有框架相比，当从单 GPU 转向多 GPU 时，Chainer 的 AUC 值出现了下降。\n该模型的输入为 112,120 张胸片图像，经过重排后尺寸为 (264, 264)。**请注意，为了使笔记本自动下载数据，您需要先安装 [Azcopy](https:\u002F\u002Fdocs.microsoft.com\u002Fen-us\u002Fazure\u002Fstorage\u002Fcommon\u002Fstorage-use-azcopy-linux#download-and-install-azcopy)，并在 Azure 门户中扩大您的操作系统磁盘容量，以确保至少有 45GB 的可用空间（胸片图像数据本身体积较大！）。这些笔记本首次下载数据可能需要超过 10 分钟。** 本笔记本采用 DenseNet-121 模型进行训练，并使用原生的数据加载器对数据进行预处理，同时执行一些增强操作（随机水平翻转以及随机裁剪至 224 像素）。\n\n### 3. 1000张图片的平均耗时：ResNet-50 - 特征提取\n\n| DL 库                                          | K80\u002FCUDA 8\u002FCuDNN 6 | P100\u002FCUDA 8\u002FCuDNN 6 |\n| --------------------------------------------------- | :----------------: | :-----------------: |\n| [Caffe2](notebooks\u002FCaffe2_Inference.ipynb)          | 14.1               | 7.9                 |\n| [Chainer](notebooks\u002FChainer_Inference.ipynb)        | 9.3                | 2.7                 |\n| [CNTK](notebooks\u002FCNTK_Inference.ipynb)              | 8.5                | 1.6                 |\n| [MXNet(Gluon)](notebooks\u002FGluon_Inference.ipynb)     |                    | 1.7                 |\n| [Keras(CNTK)](notebooks\u002FKeras_CNTK_Inference.ipynb) | 21.7               | 5.9                 |\n| [Keras(TF)](notebooks\u002FKeras_TF_Inference.ipynb)     | 10.2               | 2.9                 |\n| [Tensorflow](notebooks\u002FTensorflow_Inference.ipynb)  | 6.5                | 1.8                 |\n| [MXNet(Module API)](notebooks\u002FMXNet_Inference.ipynb)| 7.7                | 1.6                 |\n| [PyTorch](notebooks\u002FPyTorch_Inference.ipynb)        | 7.7                | 1.9                 |\n| [Julia - Knet](notebooks\u002FKnet_Inference.ipynb)      | 6.3                | ???                 |\n| [R - MXNet](notebooks\u002F.ipynb)                       | ???                | ???                 |\n| [R - Keras(TF)](notebooks\u002FKerasR_TF_Inference.ipynb)| 17                 | 7.4                 |\n\n\n预训练的 ResNet50 模型被加载，并在末尾的平均池化操作之后进行裁剪（7, 7），该操作会输出一个维度为 2048 的向量。此向量可以输入到 softmax 层，或进一步用于其他分类器，例如提升树模型，以实现迁移学习。由于采用了暖启动机制，这一仅向前传递至平均池化层的前向传播过程会被计时。*注意：批量大小保持不变，不过在 GPU 上充分填充内存将带来更显著的性能提升（对于拥有更多内存的 GPU 来说，这种提升更为明显）。*\n\n### 4. 训练时间：IMDB 上的 RNN（GRU）——情感分析\n\n| DL 库                               | K80\u002FCUDA 8\u002FCuDNN 6 | P100\u002FCUDA 8\u002FCuDNN 6 | 是否使用 CuDNN？ |\n| ---------------------------------------- | :----------------: | :----------------:  | :----------: |\n| [CNTK](notebooks\u002FCNTK_RNN.ipynb)                   | 32                 | 15                  | 是           |\n| [Keras(CNTK)](notebooks\u002FKeras_CNTK_RNN.ipynb)      | 86                 | 53                  | 否           |\n| [Keras(TF)](notebooks\u002FKeras_TF_RNN.ipynb)          | 35                 | 26                  | 是           |\n| [MXNet(Module API)](notebooks\u002FMXNet_RNN.ipynb)     | 29                 | 24                  | 是           |\n| [MXNet(Gluon API)](notebooks\u002FGluon_RNN.ipynb)      | TBA                | TBA                 | 是           |\n| [PyTorch](notebooks\u002FPyTorch_RNN.ipynb)             | 31                 | 16                  | 是           |\n| [Tensorflow](notebooks\u002FTensorflow_RNN.ipynb)       | 30                 | 22                  | 是           |\n| [Julia - Knet](notebooks\u002FKnet_RNN.ipynb)           | 29                 | ??                  | 是           |\n| [R - MXNet](notebooks\u002F.ipynb)                      | ??                 | ??                  | ???          |\n| [R - Keras(TF)](notebooks\u002FKerasR_TF_RNN.ipynb)     | 35                 | 25                  | 是           |\n\n\n该模型的输入数据来自标准的 [IMDB 电影评论数据集](http:\u002F\u002Fai.stanford.edu\u002F~amaas\u002Fdata\u002Fsentiment\u002F)，其中包含 2.5 万条训练评论和 2.5 万条测试评论，且这两类评论被均匀地划分为 2 个类别（正面\u002F负面）。处理流程遵循 [Keras](https:\u002F\u002Fgithub.com\u002Ffchollet\u002Fkeras\u002Fblob\u002Fmaster\u002Fkeras\u002Fdatasets\u002Fimdb.py) 的方法：起始字符被设置为 1，而词汇表中超出范围的词汇（词汇表大小为 3 万）则被表示为 2，因此词索引从 3 开始。每条评论均被零填充或截断，使其长度固定为 150 个单词。\n\n在可能的情况下，我们尽量采用经过 CuDNN 优化的 RNN（通过 CUDNN=True 参数加以标识），因为我们原本使用的是标准的 RNN，而该 RNN 可以轻松升级至 CuDNN 级别。例如，在 CNTK 中，我们选择使用优化过的 RNNStack，而非 Recurrence(LSTM())。这种方式速度更快，但灵活性稍低；此外，以 CNTK 为例，我们已无法再使用诸如层归一化等更为复杂的变体。在 PyTorch 中，这一功能默认已启用。至于 MXNet，我未能找到相关支持，因此转而选择了速度略慢的融合 RNN。Keras 刚刚在最近才获得了 [Cudnn 支持](https:\u002F\u002Ftwitter.com\u002Ffchollet\u002Fstatus\u002F918170264608817152)，不过仅限于 Tensorflow 后端（而非 CNTK）。TensorFlow 拥有多种 RNN 变体（包括其自定义的内核），并且有一项优秀的基准测试 [此处](http:\u002F\u002Freturnn.readthedocs.io\u002Fen\u002Flatest\u002Ftf_lstm_benchmark.html)。我将尝试更新示例，改用 CudnnLSTM 替代当前的方法。\n\n*注意：CNTK 支持 [动态轴](https:\u002F\u002Fcntk.ai\u002Fpythondocs\u002Fsequence.html)，这意味着我们无需将输入填充至 150 个单词，可以直接按原样使用；然而，由于我未能在其他框架中找到实现这一功能的方式，最终还是选择了填充——这在一定程度上对 CNTK 不公平，也未能充分展现其真正的潜力。*\n\n分类模型会生成一个大小为 (150x125) 的嵌入矩阵，随后应用 100 个门控循环单元，并将最终输出作为结果（而非输出序列，亦非隐藏状态）。欢迎提出任何关于此模型的改进建议。\n\n## 经验教训\n\n#### CNN\n\n以下内容基于我们尝试在不同框架间实现测试精度匹配，并结合所有在 GitHub 上提出的 issue\u002FPR，总结出的一些见解。\n\n1. 除 Keras 外，上述示例为了便于对比，均采用了相同的 API 级别，因此都使用了相同的生成器函数。对于 [MXNet](notebooks\u002FMXNet_CNN_highAPI.ipynb)、[Tensorflow](notebooks\u002FTensorflow_CNN_highAPI.ipynb) 和 [CNTK](notebooks\u002FCNTK_CNN_highAPI.ipynb)，我们曾尝试过更高层次的 API，即借助框架自身的训练生成器函数。然而，在这个例子中，由于整个数据集都被加载为 NumPy 数组并存储于内存中，且每轮训练仅进行一次随机打乱操作，因此性能提升微乎其微。我怀疑，框架的生成器实际上是以异步方式完成随机打乱的。有趣的是，这些框架似乎是在批次级别上进行打乱，而非以观测值为单位，因此至少在经过 10 轮训练后，测试精度略有下降。若在实际应用中存在 I\u002FO 操作，甚至需要实时进行预处理和数据增强，那么自定义生成器将对性能产生更为显著的影响。\n\n2. 在运行 CuDNN 时，我们应优先选择 [NCHW] 格式，而非通道末尾格式。Keras 最终也支持在 Tensorflow 中采用这种格式（此前 Tensorflow 一直硬编码使用 NHWC 格式，并会在每批数据后自动进行重塑）。\n\n3. 多月前，启用 CuDNN 的自动调优\u002F全面搜索参数（该参数可为固定尺寸的图像选择最高效的 CNN 算法）曾为 K80 提供了巨大的性能提升。不过如今，大多数框架已自动集成了这一功能。\n\n4. 部分框架要求在 dropout 层中提供一个布尔值，用于指示当前是训练模式还是测试模式（这一设置对测试精度产生了巨大影响，从 72% 降至 77%）。在这种情况下，不应在测试阶段应用 dropout。\n\n5. `TF_ENABLE_WINOGRAD_NONFUSED` 已不再能加速 TensorFlow 的 CNN，反而可能导致其性能下降。\n\n6. 在大多数模型中，Softmax 通常与 `cross_entropy_loss()` 一同使用；如果您的最终全连接层需要激活函数，不妨检查一下是否有必要启用它，以节省两次应用激活函数的时间。\n\n7. 不同框架对卷积核初始化器的设置可能存在差异（我发现这会对精度产生正负 1% 的影响），因此我尽量在可能的情况下使用 Xavier 或 Glorot 均匀分布的初始化方法，同时避免过于冗长的代码。\n\n8. 对于 SGD-momentum，各框架所采用的动量类型可能有所不同；我不得不关闭 `unit_gain`（该参数在 CNTK 中默认开启），以与其它框架的实现保持一致。\n\n9. Caffe2 在网络的第一层引入了一项额外优化（`no_gradient_to_input=1`），通过不为输入计算梯度，从而实现了轻微的性能提升。当然，TensorFlow 和 MXNet 可能早已默认启用了这一优化。在研究领域，以及在像 DeepDream 这样的网络中，计算该梯度可能大有裨益。\n\n10. 在最大池化之后应用 ReLU 激活函数（而非在池化之前），意味着您在维度降维之后再进行计算，从而节省了几秒钟的时间。这一优化帮助 MXNet 将运行时间缩短了 3 秒。\n\n11. 还有一些**进一步的检查**，或许对您有所帮助：\n   * 将卷积核指定为 (3) 是否会变成对称的元组 (3, 3)，或者变为一维卷积 (3, 1)？\n   * 最大池化操作的步长默认为 (1, 1)，还是与卷积核大小相同？（Keras 是这样设置的）\n   * 默认填充通常为 (0, 0)\u002Fvalid，但建议仔细检查是否为“same”填充\n   * 卷积层的默认激活函数是 “None” 还是 “ReLU”（Lasagne）\n   * 偏置初始化器可能有所不同（有时并不包含偏置）\n   * 各框架在梯度裁剪和处理无穷大\u002FNaN 值方面可能存在差异\n   * 部分框架支持稀疏标签，而非独热编码标签（如果可用，我通常会使用稀疏标签；例如，TensorFlow 提供了 `f.nn.sparse_softmax_cross_entropy_with_logits` 方法）\n   * 数据类型假设也可能有所不同——我通常会将 X 和 y 使用 float32 和 int32 类型，但例如，torch 需要使用 double 类型来将 y 转换为 torch.LongTensor(y).cuda\n   * 如果框架提供了更底层的 API，请务必在测试过程中避免通过设置 `training=False` 来计算梯度。\n\n12. 安装 Caffe2 以支持 Python 3.5 一度颇具挑战性，因此我想分享一下安装过程：\n   ```\n   # 以 root 用户身份构建\n   sudo -s\n   cd \u002Fopt\u002Fcaffe2\n   make clean\n   git pull\n   git checkout v0.8.1\n   git submodule update\n   export CPLUS_INCLUDE_PATH=\u002Fanaconda\u002Fenvs\u002Fpy35\u002Finclude\u002Fpython3.5m\n   mkdir build\n   cd build\n   echo $PATH\n   # 确认 Anaconda 不在路径中\n   cmake .. -DBLAS=MKL -DPYTHON_INCLUDE_DIR=\u002Fanaconda\u002Fenvs\u002Fpy35\u002Finclude\u002Fpython3.5m -DPYTHON_LIBRARY=\u002Fanaconda\u002Fenvs\u002Fpy35\u002Flib\u002Flibpython3.5m.so -DPYTHON_EXECUTABLE=\u002Fanaconda\u002Fenvs\u002Fpy35\u002Fbin\u002Fpython\n   make -j$(nproc)\n   make install\n   ```\n\n13. 在使用 MXNet 时，应避免在训练循环中将输出或数据赋值给 NumPy 的 `np.array`。这样做会导致数据从 GPU 复制到 CPU。相反，应使用 `mx.nd.array`，并在开始时在合适的上下文中进行分配。这一做法能够大幅提高性能。\n\n14. 在使用 MXNet 时，运算会被分配到后端引擎的队列中并进行并行化处理，因此请尽量避免在训练循环中执行任何阻塞操作。您可以添加 `nd.waitall()`，该函数将在每个 epoch 结束时强制等待所有运算完成，从而避免内存耗尽。\n\n15. 使用 MXNet\u002FGluon 时，对网络调用 `.hybridize()` 会缓存计算图，从而带来性能提升。不过，这也意味着您将无法再逐个步骤地跟踪每一步的计算过程。只有在完成网络调试后，才应使用此功能。\n\n#### RNN\n\n1. 大多数框架都提供了多种 RNN 实现与内核（例如 [Tensorflow](http:\u002F\u002Freturnn.readthedocs.io\u002Fen\u002Flatest\u002Ftf_lstm_benchmark.html)）；当我们将 RNN 实现简化至 cudnnLSTM\u002FGRU 级别时，其执行速度最快。不过，这一实现的灵活性相对较低（例如，您可能希望对某一层进行层归一化），并且在后续阶段若在 CPU 上进行推理时，可能会遇到问题。而在 cudDNN 级别，大多数框架的运行时表现非常相似。Nvidia 的一篇博客文章（[This](https:\u002F\u002Fdevblogs.nvidia.com\u002Fparallelforall\u002Foptimizing-recurrent-neural-networks-cudnn-5\u002F)）详细介绍了针对递归神经网络的多项高效 cuDNN 优化措施，例如通过“融合计算多个小矩阵为一个大矩阵，并在可能的情况下实现计算流水线，从而提高计算与内存 I\u002FO 的比值，进而提升 GPU 上的性能”。\n\n2. 似乎 RNN 最快的数据形状是 TNC——但在 [MXNet](notebooks\u002FMXNet_RNN_TNC.ipynb) 中实现这一形状仅提升了 0.5 秒，因此我选择了稍慢一些的形状，以与其它框架保持一致，并使代码更加简洁。","# DeepLearningFrameworks 快速上手指南\n\n## 环境准备\n\n- **系统**：Ubuntu 16.04+ \u002F CentOS 7+（Windows 亦可，但 GPU 驱动需自行配置）\n- **GPU**：NVIDIA 显卡，驱动 ≥ 384，CUDA ≥ 8.0，cuDNN ≥ 6\n- **Python**：3.6–3.9（推荐 3.8）\n- **内存**：≥ 8 GB（ChestXRay 任务需 ≥ 45 GB 磁盘）\n- **工具**：git、conda 或 pip、nvidia-docker（可选）\n\n## 安装步骤\n\n1. **克隆仓库**  \n   ```bash\n   git clone https:\u002F\u002Fgithub.com\u002Filkarman\u002FDeepLearningFrameworks.git\n   cd DeepLearningFrameworks\n   ```\n\n2. **创建并激活环境**（任选其一）  \n   - conda  \n     ```bash\n     conda env create -f environment.yml\n     conda activate dl-frameworks\n     ```\n   - pip（国内镜像示例）  \n     ```bash\n     python -m venv venv\n     source venv\u002Fbin\u002Factivate\n     pip install -i https:\u002F\u002Fpypi.tuna.tsinghua.edu.cn\u002Fsimple -r requirements.txt\n     ```\n\n3. **安装 GPU 加速（按需）**  \n   ```bash\n   # CUDA 11.8 + cuDNN 8 示例\n   conda install cudatoolkit=11.8 -c nvidia\n   ```\n\n4. **下载 ChestXRay 数据（可选）**  \n   先安装 azcopy：\n   ```bash\n   wget -O azcopy.tar.gz https:\u002F\u002Faka.ms\u002Fdownloadazcopy-v10-linux\n   tar -xf azcopy.tar.gz --strip-components=1\n   sudo mv azcopy \u002Fusr\u002Flocal\u002Fbin\u002F\n   ```\n   运行对应 notebook 时会自动拉取数据。\n\n## 基本使用\n\n1. **启动 Jupyter**  \n   ```bash\n   jupyter notebook\n   ```\n   浏览器打开 `http:\u002F\u002Flocalhost:8888`，选择任意框架的 notebook 即可。\n\n2. **最简示例：PyTorch CNN 训练**  \n   打开 `notebooks\u002FPyTorch_CNN.ipynb`，按顺序执行 cell：\n   ```python\n   import utils\n   import torch\n   from common.params import *\n   from common.utils import *\n\n   # 加载 CIFAR-10\n   train_loader, test_loader = utils.get_data_loaders(batch_size)\n\n   # 构建网络\n   model = utils.create_model(num_classes=10).cuda()\n\n   # 训练\n   utils.train(model, train_loader, test_loader, epochs=10)\n   ```\n\n3. **验证安装性能**  \n   运行 `notebooks\u002FTensorflow_CNN.ipynb` 或 `notebooks\u002FCNTK_CNN.ipynb`，对比 README 中的训练时间，确认 GPU 正常启用。\n\n> 提示：国内网络可设置 `export HF_ENDPOINT=https:\u002F\u002Fhf-mirror.com` 加速 Hugging Face 资源下载。","一家做医学影像 AI 的初创公司，团队 6 人，需要在 2 周内把一套在 PyTorch 上验证过的肺结节检测模型迁移到 TensorFlow Lite，以便部署到合作医院的 X 光机嵌入式设备上，并同时评估 MXNet 在云端 GPU 上的再训练性能。\n\n### 没有 DeepLearningFrameworks 时\n- 工程师 A 先花 3 天把 PyTorch 代码“翻译”成 TensorFlow，结果维度顺序搞错，推理精度掉 4%，又得返工。  \n- 为了对比 MXNet 性能，工程师 B 重新写一份数据读取、增强、多卡训练脚本，踩坑 CUDA 版本冲突，浪费 2 天。  \n- 团队缺少统一基准，各自跑出的训练时间、显存占用、准确率无法对齐，开会 1 小时都在“对数字”。  \n- 领导要求给出“在 K80 与 P100 上的差异报告”，大家临时写脚本测，结果因 batch size 不同导致结论失真，被客户质疑。  \n- 最终交付延期 5 天，嵌入式端 TensorFlow Lite 模型比预期大 30%，被迫砍功能。\n\n### 使用 DeepLearningFrameworks 后\n- 打开仓库里的 PyTorch→TensorFlow CNN 迁移示例，30 分钟照抄网络结构、权重转换脚本，精度无损。  \n- 直接跑 MXNet Gluon 与 PyTorch 的 CIFAR-10 对比 Notebook，一行命令切换 GPU 类型，10 分钟拿到 K80 vs P100 的准确训练时长与显存曲线。  \n- 所有框架共用同一套 CIFAR-10 数据与增强流程，指标对齐，团队 Slack 里直接贴图即可，无需再“对数字”。  \n- 利用现成的多卡 DenseNet-121 示例，工程师 B 把云端 4×V100 训练时间从 38 min 降到 10 min，客户演示一次通过。  \n- TensorFlow Lite 导出脚本参考了仓库的高阶 API 写法，模型大小减少 25%，按期上线，医院现场推理延迟 \u003C150 ms。\n\nDeepLearningFrameworks 让跨框架迁移与性能验证像查字典一样简单，把 2 周折腾变成 2 天搞定。","https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Filkarman_DeepLearningFrameworks_87876be4.png","ilkarman","Ilia Karmanov","https:\u002F\u002Foss.gittoolsai.com\u002Favatars\u002Filkarman_20ada8bb.jpg",null,"Microsoft","London","https:\u002F\u002Fwww.linkedin.com\u002Fin\u002Filia-karmanov-09aa588b\u002F","https:\u002F\u002Fgithub.com\u002Filkarman",[84,88,92],{"name":85,"color":86,"percentage":87},"Jupyter Notebook","#DA5B0B",95.5,{"name":89,"color":90,"percentage":91},"Python","#3572A5",3.1,{"name":93,"color":94,"percentage":95},"R","#198CE7",1.4,1656,354,"2026-02-28T18:04:24","MIT","Linux","需要 NVIDIA GPU，K80\u002FP100\u002FV100 均可，显存 ≥8GB，CUDA 8\u002F9，cuDNN 6\u002F7","≥16GB（ChestXRay 任务需额外 45GB 磁盘空间）",{"notes":104,"python":105,"dependencies":106},"官方示例在 Azure Deep Learning VM 上运行，需安装 Azcopy 并预留 45GB 以上磁盘空间用于下载 Chest X-ray 数据集；多 GPU 训练需 4×V100 环境","未说明",[107,108,109,110,111,112,113,114,115],"caffe2","chainer","cntk","mxnet","keras","tensorflow","pytorch","julia-knet","r-keras",[14,13,54],"2026-03-27T02:49:30.150509","2026-04-06T05:15:20.127839",[120,125,130,135,140,145],{"id":121,"question_zh":122,"answer_zh":123,"source_url":124},6216,"为什么 MXNet 在多 GPU 多标签任务中的 AUC 比其他框架低？","主要原因有两点：\n1. 数据格式：需要通过 im2rec 脚本添加 class-labels 标志，使标签形状为 (BATCH, 14) 而不是 (BATCH)，否则无法正确处理多标签。\n2. 损失函数：需要将损失从默认设置改为 sum 或 average 模式。\n\n参考实现：https:\u002F\u002Fgithub.com\u002Filkarman\u002FDeepLearningFrameworks\u002Fpull\u002F81 提供了 Gluon 多 GPU 的完整示例。","https:\u002F\u002Fgithub.com\u002Filkarman\u002FDeepLearningFrameworks\u002Fissues\u002F69",{"id":126,"question_zh":127,"answer_zh":128,"source_url":129},6217,"TensorFlow 使用 CuDNN GRU 后准确率从 0.86 降到 0.5 怎么办？","问题出在权重初始化范围过大。解决方案：\n1. 将 tf.random_uniform 的范围从默认的 [0, 1] 改为 [-0.1, 0.1]\n2. 示例代码：\n```python\nparams = tf.Variable(tf.random_uniform([params_size_t], -0.1, 0.1), validate_shape=False)\n```\n修改后准确率可恢复到 0.85 左右。","https:\u002F\u002Fgithub.com\u002Filkarman\u002FDeepLearningFrameworks\u002Fissues\u002F29",{"id":131,"question_zh":132,"answer_zh":133,"source_url":134},6218,"为什么框架间的性能差异主要来自 I\u002FO 而非计算？","关键发现：\n1. 使用 feed_dict 方式提供数据会造成 2-4 秒的额外开销\n2. 正确做法应使用数据库或输入迭代器，这样底层可以实现预取等优化\n3. 对于 TensorFlow，设置环境变量可提升性能：\n```bash\nexport TF_ENABLE_WINOGRAD_NONFUSED=1\n```\n这个设置可将训练时间从 320s 降到 180s（K40 GPU）。","https:\u002F\u002Fgithub.com\u002Filkarman\u002FDeepLearningFrameworks\u002Fissues\u002F2",{"id":136,"question_zh":137,"answer_zh":138,"source_url":139},6219,"如何扩展基准测试到多 GPU 和多节点？","项目已启动多 GPU 支持：\n1. 多 GPU 示例：https:\u002F\u002Fgithub.com\u002Filkarman\u002FDeepLearningFrameworks\u002Fpull\u002F53\n2. 多节点测试建议：随着云服务商 ML 平台的发展，多节点扩展性比多 GPU 更重要\n3. 评估维度应包括：异步数据增强、数据并行训练、自定义层创建、TensorBoard 集成、预训练模型可用性等，而非仅关注基础 CNN 的计时。","https:\u002F\u002Fgithub.com\u002Filkarman\u002FDeepLearningFrameworks\u002Fissues\u002F50",{"id":141,"question_zh":142,"answer_zh":143,"source_url":144},6220,"下一个基准测试应该关注什么模型？","社区投票结果：\n1. 最受欢迎：RNN\u002FLSTM（适用于普通用户）\n2. 研究向：实现非标准循环单元以测试框架优化能力\n3. 不推荐：强化学习（RL 本身过于复杂，不同框架需要不同实现选择）\n4. 数据选择：时间序列\u002F音频\u002F文本更多是展示用途，对框架比较影响较小。","https:\u002F\u002Fgithub.com\u002Filkarman\u002FDeepLearningFrameworks\u002Fissues\u002F14",{"id":146,"question_zh":147,"answer_zh":148,"source_url":149},6221,"MXNet 如何使用高级 API 的 .fit() 方法？","项目已更新 MXNet 示例以匹配 TensorFlow 和 CNTK 的使用方式：\n1. 使用 High-level API 的 .fit() 方法\n2. 参考实现：https:\u002F\u002Fgithub.com\u002Filkarman\u002FDeepLearningFrameworks\u002Ftree\u002Fmxnetdev\n3. 注意：直接合并到主分支会丢失贡献者信息，建议通过 PR 方式合并以保持贡献记录。","https:\u002F\u002Fgithub.com\u002Filkarman\u002FDeepLearningFrameworks\u002Fissues\u002F55",[]]