mediapipe-nightly 0.10.21.post20250114__cp310-cp310-manylinux_2_28_x86_64.whl
Sign up to get free protection for your applications and to get access to all the features.
- mediapipe/__init__.py +26 -0
- mediapipe/calculators/__init__.py +0 -0
- mediapipe/calculators/audio/__init__.py +0 -0
- mediapipe/calculators/audio/mfcc_mel_calculators_pb2.py +33 -0
- mediapipe/calculators/audio/rational_factor_resample_calculator_pb2.py +33 -0
- mediapipe/calculators/audio/spectrogram_calculator_pb2.py +37 -0
- mediapipe/calculators/audio/stabilized_log_calculator_pb2.py +31 -0
- mediapipe/calculators/audio/time_series_framer_calculator_pb2.py +33 -0
- mediapipe/calculators/core/__init__.py +0 -0
- mediapipe/calculators/core/bypass_calculator_pb2.py +31 -0
- mediapipe/calculators/core/clip_vector_size_calculator_pb2.py +31 -0
- mediapipe/calculators/core/concatenate_vector_calculator_pb2.py +31 -0
- mediapipe/calculators/core/constant_side_packet_calculator_pb2.py +39 -0
- mediapipe/calculators/core/dequantize_byte_array_calculator_pb2.py +31 -0
- mediapipe/calculators/core/flow_limiter_calculator_pb2.py +32 -0
- mediapipe/calculators/core/gate_calculator_pb2.py +33 -0
- mediapipe/calculators/core/get_vector_item_calculator_pb2.py +31 -0
- mediapipe/calculators/core/graph_profile_calculator_pb2.py +31 -0
- mediapipe/calculators/core/packet_cloner_calculator_pb2.py +31 -0
- mediapipe/calculators/core/packet_resampler_calculator_pb2.py +33 -0
- mediapipe/calculators/core/packet_thinner_calculator_pb2.py +33 -0
- mediapipe/calculators/core/quantize_float_vector_calculator_pb2.py +31 -0
- mediapipe/calculators/core/sequence_shift_calculator_pb2.py +31 -0
- mediapipe/calculators/core/split_vector_calculator_pb2.py +33 -0
- mediapipe/calculators/image/__init__.py +0 -0
- mediapipe/calculators/image/bilateral_filter_calculator_pb2.py +31 -0
- mediapipe/calculators/image/feature_detector_calculator_pb2.py +31 -0
- mediapipe/calculators/image/image_clone_calculator_pb2.py +31 -0
- mediapipe/calculators/image/image_cropping_calculator_pb2.py +33 -0
- mediapipe/calculators/image/image_transformation_calculator_pb2.py +38 -0
- mediapipe/calculators/image/mask_overlay_calculator_pb2.py +33 -0
- mediapipe/calculators/image/opencv_encoded_image_to_image_frame_calculator_pb2.py +31 -0
- mediapipe/calculators/image/opencv_image_encoder_calculator_pb2.py +35 -0
- mediapipe/calculators/image/recolor_calculator_pb2.py +34 -0
- mediapipe/calculators/image/rotation_mode_pb2.py +29 -0
- mediapipe/calculators/image/scale_image_calculator_pb2.py +34 -0
- mediapipe/calculators/image/segmentation_smoothing_calculator_pb2.py +31 -0
- mediapipe/calculators/image/set_alpha_calculator_pb2.py +31 -0
- mediapipe/calculators/image/warp_affine_calculator_pb2.py +36 -0
- mediapipe/calculators/internal/__init__.py +0 -0
- mediapipe/calculators/internal/callback_packet_calculator_pb2.py +33 -0
- mediapipe/calculators/tensor/__init__.py +0 -0
- mediapipe/calculators/tensor/audio_to_tensor_calculator_pb2.py +35 -0
- mediapipe/calculators/tensor/bert_preprocessor_calculator_pb2.py +31 -0
- mediapipe/calculators/tensor/feedback_tensors_calculator_pb2.py +37 -0
- mediapipe/calculators/tensor/image_to_tensor_calculator_pb2.py +40 -0
- mediapipe/calculators/tensor/inference_calculator_pb2.py +63 -0
- mediapipe/calculators/tensor/landmarks_to_tensor_calculator_pb2.py +33 -0
- mediapipe/calculators/tensor/regex_preprocessor_calculator_pb2.py +31 -0
- mediapipe/calculators/tensor/tensor_converter_calculator_pb2.py +34 -0
- mediapipe/calculators/tensor/tensor_to_joints_calculator_pb2.py +31 -0
- mediapipe/calculators/tensor/tensors_readback_calculator_pb2.py +35 -0
- mediapipe/calculators/tensor/tensors_to_audio_calculator_pb2.py +33 -0
- mediapipe/calculators/tensor/tensors_to_classification_calculator_pb2.py +44 -0
- mediapipe/calculators/tensor/tensors_to_detections_calculator_pb2.py +39 -0
- mediapipe/calculators/tensor/tensors_to_floats_calculator_pb2.py +33 -0
- mediapipe/calculators/tensor/tensors_to_landmarks_calculator_pb2.py +33 -0
- mediapipe/calculators/tensor/tensors_to_segmentation_calculator_pb2.py +34 -0
- mediapipe/calculators/tensor/vector_to_tensor_calculator_pb2.py +27 -0
- mediapipe/calculators/tflite/__init__.py +0 -0
- mediapipe/calculators/tflite/ssd_anchors_calculator_pb2.py +32 -0
- mediapipe/calculators/tflite/tflite_converter_calculator_pb2.py +33 -0
- mediapipe/calculators/tflite/tflite_custom_op_resolver_calculator_pb2.py +31 -0
- mediapipe/calculators/tflite/tflite_inference_calculator_pb2.py +49 -0
- mediapipe/calculators/tflite/tflite_tensors_to_classification_calculator_pb2.py +31 -0
- mediapipe/calculators/tflite/tflite_tensors_to_detections_calculator_pb2.py +31 -0
- mediapipe/calculators/tflite/tflite_tensors_to_landmarks_calculator_pb2.py +33 -0
- mediapipe/calculators/tflite/tflite_tensors_to_segmentation_calculator_pb2.py +31 -0
- mediapipe/calculators/util/__init__.py +0 -0
- mediapipe/calculators/util/align_hand_to_pose_in_world_calculator_pb2.py +31 -0
- mediapipe/calculators/util/annotation_overlay_calculator_pb2.py +32 -0
- mediapipe/calculators/util/association_calculator_pb2.py +31 -0
- mediapipe/calculators/util/collection_has_min_size_calculator_pb2.py +31 -0
- mediapipe/calculators/util/combine_joints_calculator_pb2.py +36 -0
- mediapipe/calculators/util/detection_label_id_to_text_calculator_pb2.py +36 -0
- mediapipe/calculators/util/detections_to_rects_calculator_pb2.py +33 -0
- mediapipe/calculators/util/detections_to_render_data_calculator_pb2.py +33 -0
- mediapipe/calculators/util/face_to_rect_calculator_pb2.py +26 -0
- mediapipe/calculators/util/filter_detections_calculator_pb2.py +31 -0
- mediapipe/calculators/util/flat_color_image_calculator_pb2.py +32 -0
- mediapipe/calculators/util/labels_to_render_data_calculator_pb2.py +34 -0
- mediapipe/calculators/util/landmark_projection_calculator_pb2.py +31 -0
- mediapipe/calculators/util/landmarks_refinement_calculator_pb2.py +41 -0
- mediapipe/calculators/util/landmarks_smoothing_calculator_pb2.py +33 -0
- mediapipe/calculators/util/landmarks_to_detection_calculator_pb2.py +31 -0
- mediapipe/calculators/util/landmarks_to_floats_calculator_pb2.py +31 -0
- mediapipe/calculators/util/landmarks_to_render_data_calculator_pb2.py +32 -0
- mediapipe/calculators/util/landmarks_transformation_calculator_pb2.py +37 -0
- mediapipe/calculators/util/latency_pb2.py +26 -0
- mediapipe/calculators/util/local_file_contents_calculator_pb2.py +31 -0
- mediapipe/calculators/util/logic_calculator_pb2.py +34 -0
- mediapipe/calculators/util/non_max_suppression_calculator_pb2.py +35 -0
- mediapipe/calculators/util/packet_frequency_calculator_pb2.py +31 -0
- mediapipe/calculators/util/packet_frequency_pb2.py +26 -0
- mediapipe/calculators/util/packet_latency_calculator_pb2.py +31 -0
- mediapipe/calculators/util/rect_to_render_data_calculator_pb2.py +32 -0
- mediapipe/calculators/util/rect_to_render_scale_calculator_pb2.py +31 -0
- mediapipe/calculators/util/rect_transformation_calculator_pb2.py +31 -0
- mediapipe/calculators/util/refine_landmarks_from_heatmap_calculator_pb2.py +31 -0
- mediapipe/calculators/util/resource_provider_calculator_pb2.py +28 -0
- mediapipe/calculators/util/set_joints_visibility_calculator_pb2.py +41 -0
- mediapipe/calculators/util/thresholding_calculator_pb2.py +31 -0
- mediapipe/calculators/util/timed_box_list_id_to_label_calculator_pb2.py +31 -0
- mediapipe/calculators/util/timed_box_list_to_render_data_calculator_pb2.py +32 -0
- mediapipe/calculators/util/top_k_scores_calculator_pb2.py +31 -0
- mediapipe/calculators/util/visibility_copy_calculator_pb2.py +27 -0
- mediapipe/calculators/util/visibility_smoothing_calculator_pb2.py +31 -0
- mediapipe/calculators/video/__init__.py +0 -0
- mediapipe/calculators/video/box_detector_calculator_pb2.py +32 -0
- mediapipe/calculators/video/box_tracker_calculator_pb2.py +32 -0
- mediapipe/calculators/video/flow_packager_calculator_pb2.py +32 -0
- mediapipe/calculators/video/flow_to_image_calculator_pb2.py +31 -0
- mediapipe/calculators/video/motion_analysis_calculator_pb2.py +42 -0
- mediapipe/calculators/video/opencv_video_encoder_calculator_pb2.py +31 -0
- mediapipe/calculators/video/tool/__init__.py +0 -0
- mediapipe/calculators/video/tool/flow_quantizer_model_pb2.py +26 -0
- mediapipe/calculators/video/tracked_detection_manager_calculator_pb2.py +32 -0
- mediapipe/calculators/video/video_pre_stream_calculator_pb2.py +35 -0
- mediapipe/examples/__init__.py +14 -0
- mediapipe/examples/desktop/__init__.py +14 -0
- mediapipe/framework/__init__.py +0 -0
- mediapipe/framework/calculator_options_pb2.py +29 -0
- mediapipe/framework/calculator_pb2.py +59 -0
- mediapipe/framework/calculator_profile_pb2.py +48 -0
- mediapipe/framework/deps/__init__.py +0 -0
- mediapipe/framework/deps/proto_descriptor_pb2.py +29 -0
- mediapipe/framework/formats/__init__.py +0 -0
- mediapipe/framework/formats/affine_transform_data_pb2.py +28 -0
- mediapipe/framework/formats/annotation/__init__.py +0 -0
- mediapipe/framework/formats/annotation/locus_pb2.py +32 -0
- mediapipe/framework/formats/annotation/rasterization_pb2.py +29 -0
- mediapipe/framework/formats/body_rig_pb2.py +28 -0
- mediapipe/framework/formats/classification_pb2.py +31 -0
- mediapipe/framework/formats/detection_pb2.py +36 -0
- mediapipe/framework/formats/image_file_properties_pb2.py +26 -0
- mediapipe/framework/formats/image_format_pb2.py +29 -0
- mediapipe/framework/formats/landmark_pb2.py +37 -0
- mediapipe/framework/formats/location_data_pb2.py +38 -0
- mediapipe/framework/formats/matrix_data_pb2.py +31 -0
- mediapipe/framework/formats/motion/__init__.py +0 -0
- mediapipe/framework/formats/motion/optical_flow_field_data_pb2.py +30 -0
- mediapipe/framework/formats/object_detection/__init__.py +0 -0
- mediapipe/framework/formats/object_detection/anchor_pb2.py +26 -0
- mediapipe/framework/formats/rect_pb2.py +29 -0
- mediapipe/framework/formats/time_series_header_pb2.py +28 -0
- mediapipe/framework/graph_runtime_info_pb2.py +31 -0
- mediapipe/framework/mediapipe_options_pb2.py +27 -0
- mediapipe/framework/packet_factory_pb2.py +31 -0
- mediapipe/framework/packet_generator_pb2.py +33 -0
- mediapipe/framework/status_handler_pb2.py +28 -0
- mediapipe/framework/stream_handler/__init__.py +0 -0
- mediapipe/framework/stream_handler/default_input_stream_handler_pb2.py +27 -0
- mediapipe/framework/stream_handler/fixed_size_input_stream_handler_pb2.py +27 -0
- mediapipe/framework/stream_handler/sync_set_input_stream_handler_pb2.py +29 -0
- mediapipe/framework/stream_handler/timestamp_align_input_stream_handler_pb2.py +27 -0
- mediapipe/framework/stream_handler_pb2.py +30 -0
- mediapipe/framework/test_calculators_pb2.py +31 -0
- mediapipe/framework/thread_pool_executor_pb2.py +29 -0
- mediapipe/framework/tool/__init__.py +0 -0
- mediapipe/framework/tool/calculator_graph_template_pb2.py +44 -0
- mediapipe/framework/tool/field_data_pb2.py +28 -0
- mediapipe/framework/tool/node_chain_subgraph_pb2.py +31 -0
- mediapipe/framework/tool/packet_generator_wrapper_calculator_pb2.py +28 -0
- mediapipe/framework/tool/source_pb2.py +33 -0
- mediapipe/framework/tool/switch_container_pb2.py +32 -0
- mediapipe/gpu/__init__.py +0 -0
- mediapipe/gpu/copy_calculator_pb2.py +33 -0
- mediapipe/gpu/gl_animation_overlay_calculator_pb2.py +31 -0
- mediapipe/gpu/gl_context_options_pb2.py +31 -0
- mediapipe/gpu/gl_scaler_calculator_pb2.py +32 -0
- mediapipe/gpu/gl_surface_sink_calculator_pb2.py +32 -0
- mediapipe/gpu/gpu_origin_pb2.py +29 -0
- mediapipe/gpu/scale_mode_pb2.py +28 -0
- mediapipe/model_maker/__init__.py +27 -0
- mediapipe/model_maker/setup.py +107 -0
- mediapipe/modules/__init__.py +0 -0
- mediapipe/modules/face_detection/__init__.py +0 -0
- mediapipe/modules/face_detection/face_detection_full_range_cpu.binarypb +0 -0
- mediapipe/modules/face_detection/face_detection_full_range_sparse.tflite +0 -0
- mediapipe/modules/face_detection/face_detection_pb2.py +30 -0
- mediapipe/modules/face_detection/face_detection_short_range.tflite +0 -0
- mediapipe/modules/face_detection/face_detection_short_range_cpu.binarypb +0 -0
- mediapipe/modules/face_geometry/__init__.py +0 -0
- mediapipe/modules/face_geometry/data/__init__.py +0 -0
- mediapipe/modules/face_geometry/effect_renderer_calculator_pb2.py +27 -0
- mediapipe/modules/face_geometry/env_generator_calculator_pb2.py +28 -0
- mediapipe/modules/face_geometry/geometry_pipeline_calculator_pb2.py +27 -0
- mediapipe/modules/face_geometry/libs/__init__.py +0 -0
- mediapipe/modules/face_geometry/protos/__init__.py +0 -0
- mediapipe/modules/face_geometry/protos/environment_pb2.py +31 -0
- mediapipe/modules/face_geometry/protos/face_geometry_pb2.py +29 -0
- mediapipe/modules/face_geometry/protos/geometry_pipeline_metadata_pb2.py +32 -0
- mediapipe/modules/face_geometry/protos/mesh_3d_pb2.py +31 -0
- mediapipe/modules/face_landmark/__init__.py +0 -0
- mediapipe/modules/face_landmark/face_landmark.tflite +0 -0
- mediapipe/modules/face_landmark/face_landmark_front_cpu.binarypb +0 -0
- mediapipe/modules/face_landmark/face_landmark_with_attention.tflite +0 -0
- mediapipe/modules/hand_landmark/__init__.py +0 -0
- mediapipe/modules/hand_landmark/calculators/__init__.py +0 -0
- mediapipe/modules/hand_landmark/hand_landmark_full.tflite +0 -0
- mediapipe/modules/hand_landmark/hand_landmark_lite.tflite +0 -0
- mediapipe/modules/hand_landmark/hand_landmark_tracking_cpu.binarypb +0 -0
- mediapipe/modules/hand_landmark/handedness.txt +2 -0
- mediapipe/modules/holistic_landmark/__init__.py +0 -0
- mediapipe/modules/holistic_landmark/calculators/__init__.py +0 -0
- mediapipe/modules/holistic_landmark/calculators/roi_tracking_calculator_pb2.py +37 -0
- mediapipe/modules/holistic_landmark/hand_recrop.tflite +0 -0
- mediapipe/modules/holistic_landmark/holistic_landmark_cpu.binarypb +0 -0
- mediapipe/modules/iris_landmark/__init__.py +0 -0
- mediapipe/modules/iris_landmark/iris_landmark.tflite +0 -0
- mediapipe/modules/objectron/__init__.py +0 -0
- mediapipe/modules/objectron/calculators/__init__.py +0 -0
- mediapipe/modules/objectron/calculators/a_r_capture_metadata_pb2.py +102 -0
- mediapipe/modules/objectron/calculators/annotation_data_pb2.py +38 -0
- mediapipe/modules/objectron/calculators/belief_decoder_config_pb2.py +28 -0
- mediapipe/modules/objectron/calculators/camera_parameters_pb2.py +30 -0
- mediapipe/modules/objectron/calculators/filter_detection_calculator_pb2.py +35 -0
- mediapipe/modules/objectron/calculators/frame_annotation_to_rect_calculator_pb2.py +31 -0
- mediapipe/modules/objectron/calculators/frame_annotation_tracker_calculator_pb2.py +31 -0
- mediapipe/modules/objectron/calculators/lift_2d_frame_annotation_to_3d_calculator_pb2.py +32 -0
- mediapipe/modules/objectron/calculators/object_pb2.py +38 -0
- mediapipe/modules/objectron/calculators/tensors_to_objects_calculator_pb2.py +32 -0
- mediapipe/modules/objectron/calculators/tflite_tensors_to_objects_calculator_pb2.py +32 -0
- mediapipe/modules/objectron/object_detection_oidv4_labelmap.txt +24 -0
- mediapipe/modules/objectron/objectron_cpu.binarypb +0 -0
- mediapipe/modules/palm_detection/__init__.py +0 -0
- mediapipe/modules/palm_detection/palm_detection_full.tflite +0 -0
- mediapipe/modules/palm_detection/palm_detection_lite.tflite +0 -0
- mediapipe/modules/pose_detection/__init__.py +0 -0
- mediapipe/modules/pose_detection/pose_detection.tflite +0 -0
- mediapipe/modules/pose_landmark/__init__.py +0 -0
- mediapipe/modules/pose_landmark/pose_landmark_cpu.binarypb +0 -0
- mediapipe/modules/pose_landmark/pose_landmark_full.tflite +0 -0
- mediapipe/modules/selfie_segmentation/__init__.py +0 -0
- mediapipe/modules/selfie_segmentation/selfie_segmentation.tflite +0 -0
- mediapipe/modules/selfie_segmentation/selfie_segmentation_cpu.binarypb +0 -0
- mediapipe/modules/selfie_segmentation/selfie_segmentation_landscape.tflite +0 -0
- mediapipe/python/__init__.py +29 -0
- mediapipe/python/_framework_bindings.cpython-310-x86_64-linux-gnu.so +0 -0
- mediapipe/python/calculator_graph_test.py +251 -0
- mediapipe/python/image_frame_test.py +194 -0
- mediapipe/python/image_test.py +218 -0
- mediapipe/python/packet_creator.py +275 -0
- mediapipe/python/packet_getter.py +120 -0
- mediapipe/python/packet_test.py +533 -0
- mediapipe/python/solution_base.py +604 -0
- mediapipe/python/solution_base_test.py +396 -0
- mediapipe/python/solutions/__init__.py +27 -0
- mediapipe/python/solutions/download_utils.py +37 -0
- mediapipe/python/solutions/drawing_styles.py +249 -0
- mediapipe/python/solutions/drawing_utils.py +320 -0
- mediapipe/python/solutions/drawing_utils_test.py +258 -0
- mediapipe/python/solutions/face_detection.py +105 -0
- mediapipe/python/solutions/face_detection_test.py +92 -0
- mediapipe/python/solutions/face_mesh.py +125 -0
- mediapipe/python/solutions/face_mesh_connections.py +500 -0
- mediapipe/python/solutions/face_mesh_test.py +170 -0
- mediapipe/python/solutions/hands.py +153 -0
- mediapipe/python/solutions/hands_connections.py +32 -0
- mediapipe/python/solutions/hands_test.py +219 -0
- mediapipe/python/solutions/holistic.py +167 -0
- mediapipe/python/solutions/holistic_test.py +142 -0
- mediapipe/python/solutions/objectron.py +288 -0
- mediapipe/python/solutions/objectron_test.py +81 -0
- mediapipe/python/solutions/pose.py +192 -0
- mediapipe/python/solutions/pose_connections.py +22 -0
- mediapipe/python/solutions/pose_test.py +262 -0
- mediapipe/python/solutions/selfie_segmentation.py +76 -0
- mediapipe/python/solutions/selfie_segmentation_test.py +68 -0
- mediapipe/python/timestamp_test.py +78 -0
- mediapipe/tasks/__init__.py +14 -0
- mediapipe/tasks/cc/__init__.py +0 -0
- mediapipe/tasks/cc/audio/__init__.py +0 -0
- mediapipe/tasks/cc/audio/audio_classifier/__init__.py +0 -0
- mediapipe/tasks/cc/audio/audio_classifier/proto/__init__.py +0 -0
- mediapipe/tasks/cc/audio/audio_classifier/proto/audio_classifier_graph_options_pb2.py +35 -0
- mediapipe/tasks/cc/audio/audio_embedder/__init__.py +0 -0
- mediapipe/tasks/cc/audio/audio_embedder/proto/__init__.py +0 -0
- mediapipe/tasks/cc/audio/audio_embedder/proto/audio_embedder_graph_options_pb2.py +35 -0
- mediapipe/tasks/cc/audio/core/__init__.py +0 -0
- mediapipe/tasks/cc/audio/utils/__init__.py +0 -0
- mediapipe/tasks/cc/components/__init__.py +0 -0
- mediapipe/tasks/cc/components/calculators/__init__.py +0 -0
- mediapipe/tasks/cc/components/calculators/classification_aggregation_calculator_pb2.py +31 -0
- mediapipe/tasks/cc/components/calculators/score_calibration_calculator_pb2.py +35 -0
- mediapipe/tasks/cc/components/calculators/tensors_to_embeddings_calculator_pb2.py +32 -0
- mediapipe/tasks/cc/components/containers/__init__.py +0 -0
- mediapipe/tasks/cc/components/containers/proto/__init__.py +0 -0
- mediapipe/tasks/cc/components/containers/proto/classifications_pb2.py +30 -0
- mediapipe/tasks/cc/components/containers/proto/embeddings_pb2.py +35 -0
- mediapipe/tasks/cc/components/containers/proto/landmarks_detection_result_pb2.py +32 -0
- mediapipe/tasks/cc/components/processors/__init__.py +0 -0
- mediapipe/tasks/cc/components/processors/proto/__init__.py +0 -0
- mediapipe/tasks/cc/components/processors/proto/classification_postprocessing_graph_options_pb2.py +38 -0
- mediapipe/tasks/cc/components/processors/proto/classifier_options_pb2.py +27 -0
- mediapipe/tasks/cc/components/processors/proto/detection_postprocessing_graph_options_pb2.py +36 -0
- mediapipe/tasks/cc/components/processors/proto/detector_options_pb2.py +27 -0
- mediapipe/tasks/cc/components/processors/proto/embedder_options_pb2.py +27 -0
- mediapipe/tasks/cc/components/processors/proto/embedding_postprocessing_graph_options_pb2.py +32 -0
- mediapipe/tasks/cc/components/processors/proto/image_preprocessing_graph_options_pb2.py +34 -0
- mediapipe/tasks/cc/components/processors/proto/text_model_type_pb2.py +28 -0
- mediapipe/tasks/cc/components/processors/proto/text_preprocessing_graph_options_pb2.py +32 -0
- mediapipe/tasks/cc/components/utils/__init__.py +0 -0
- mediapipe/tasks/cc/core/__init__.py +0 -0
- mediapipe/tasks/cc/core/proto/__init__.py +0 -0
- mediapipe/tasks/cc/core/proto/acceleration_pb2.py +28 -0
- mediapipe/tasks/cc/core/proto/base_options_pb2.py +30 -0
- mediapipe/tasks/cc/core/proto/external_file_pb2.py +31 -0
- mediapipe/tasks/cc/core/proto/inference_subgraph_pb2.py +32 -0
- mediapipe/tasks/cc/core/proto/model_resources_calculator_pb2.py +32 -0
- mediapipe/tasks/cc/genai/__init__.py +0 -0
- mediapipe/tasks/cc/genai/inference/__init__.py +0 -0
- mediapipe/tasks/cc/genai/inference/c/__init__.py +0 -0
- mediapipe/tasks/cc/genai/inference/calculators/__init__.py +0 -0
- mediapipe/tasks/cc/genai/inference/calculators/detokenizer_calculator_pb2.py +27 -0
- mediapipe/tasks/cc/genai/inference/calculators/llm_gpu_calculator_pb2.py +32 -0
- mediapipe/tasks/cc/genai/inference/calculators/model_data_calculator_pb2.py +27 -0
- mediapipe/tasks/cc/genai/inference/calculators/tokenizer_calculator_pb2.py +29 -0
- mediapipe/tasks/cc/genai/inference/common/__init__.py +0 -0
- mediapipe/tasks/cc/genai/inference/proto/__init__.py +0 -0
- mediapipe/tasks/cc/genai/inference/proto/llm_file_metadata_pb2.py +32 -0
- mediapipe/tasks/cc/genai/inference/proto/llm_params_pb2.py +33 -0
- mediapipe/tasks/cc/genai/inference/proto/prompt_template_pb2.py +27 -0
- mediapipe/tasks/cc/genai/inference/proto/sampler_params_pb2.py +29 -0
- mediapipe/tasks/cc/genai/inference/proto/transformer_params_pb2.py +45 -0
- mediapipe/tasks/cc/genai/inference/utils/__init__.py +0 -0
- mediapipe/tasks/cc/genai/inference/utils/llm_utils/__init__.py +0 -0
- mediapipe/tasks/cc/genai/inference/utils/xnn_utils/__init__.py +0 -0
- mediapipe/tasks/cc/metadata/__init__.py +0 -0
- mediapipe/tasks/cc/metadata/python/__init__.py +0 -0
- mediapipe/tasks/cc/metadata/python/_pywrap_metadata_version.cpython-310-x86_64-linux-gnu.so +0 -0
- mediapipe/tasks/cc/metadata/tests/__init__.py +0 -0
- mediapipe/tasks/cc/metadata/utils/__init__.py +0 -0
- mediapipe/tasks/cc/text/__init__.py +0 -0
- mediapipe/tasks/cc/text/custom_ops/__init__.py +0 -0
- mediapipe/tasks/cc/text/custom_ops/ragged/__init__.py +0 -0
- mediapipe/tasks/cc/text/custom_ops/sentencepiece/__init__.py +0 -0
- mediapipe/tasks/cc/text/custom_ops/sentencepiece/testdata/__init__.py +0 -0
- mediapipe/tasks/cc/text/language_detector/__init__.py +0 -0
- mediapipe/tasks/cc/text/language_detector/custom_ops/__init__.py +0 -0
- mediapipe/tasks/cc/text/language_detector/custom_ops/utils/__init__.py +0 -0
- mediapipe/tasks/cc/text/language_detector/custom_ops/utils/hash/__init__.py +0 -0
- mediapipe/tasks/cc/text/language_detector/custom_ops/utils/utf/__init__.py +0 -0
- mediapipe/tasks/cc/text/text_classifier/__init__.py +0 -0
- mediapipe/tasks/cc/text/text_classifier/proto/__init__.py +0 -0
- mediapipe/tasks/cc/text/text_classifier/proto/text_classifier_graph_options_pb2.py +35 -0
- mediapipe/tasks/cc/text/text_embedder/__init__.py +0 -0
- mediapipe/tasks/cc/text/text_embedder/proto/__init__.py +0 -0
- mediapipe/tasks/cc/text/text_embedder/proto/text_embedder_graph_options_pb2.py +35 -0
- mediapipe/tasks/cc/text/tokenizers/__init__.py +0 -0
- mediapipe/tasks/cc/text/utils/__init__.py +0 -0
- mediapipe/tasks/cc/vision/__init__.py +0 -0
- mediapipe/tasks/cc/vision/core/__init__.py +0 -0
- mediapipe/tasks/cc/vision/custom_ops/__init__.py +0 -0
- mediapipe/tasks/cc/vision/face_detector/__init__.py +0 -0
- mediapipe/tasks/cc/vision/face_detector/proto/__init__.py +0 -0
- mediapipe/tasks/cc/vision/face_detector/proto/face_detector_graph_options_pb2.py +34 -0
- mediapipe/tasks/cc/vision/face_geometry/__init__.py +0 -0
- mediapipe/tasks/cc/vision/face_geometry/calculators/__init__.py +0 -0
- mediapipe/tasks/cc/vision/face_geometry/calculators/env_generator_calculator_pb2.py +28 -0
- mediapipe/tasks/cc/vision/face_geometry/calculators/geometry_pipeline_calculator_pb2.py +29 -0
- mediapipe/tasks/cc/vision/face_geometry/data/__init__.py +0 -0
- mediapipe/tasks/cc/vision/face_geometry/libs/__init__.py +0 -0
- mediapipe/tasks/cc/vision/face_geometry/proto/__init__.py +0 -0
- mediapipe/tasks/cc/vision/face_geometry/proto/environment_pb2.py +31 -0
- mediapipe/tasks/cc/vision/face_geometry/proto/face_geometry_graph_options_pb2.py +29 -0
- mediapipe/tasks/cc/vision/face_geometry/proto/face_geometry_pb2.py +29 -0
- mediapipe/tasks/cc/vision/face_geometry/proto/geometry_pipeline_metadata_pb2.py +32 -0
- mediapipe/tasks/cc/vision/face_geometry/proto/mesh_3d_pb2.py +31 -0
- mediapipe/tasks/cc/vision/face_landmarker/__init__.py +0 -0
- mediapipe/tasks/cc/vision/face_landmarker/proto/__init__.py +0 -0
- mediapipe/tasks/cc/vision/face_landmarker/proto/face_blendshapes_graph_options_pb2.py +34 -0
- mediapipe/tasks/cc/vision/face_landmarker/proto/face_landmarker_graph_options_pb2.py +37 -0
- mediapipe/tasks/cc/vision/face_landmarker/proto/face_landmarks_detector_graph_options_pb2.py +35 -0
- mediapipe/tasks/cc/vision/face_landmarker/proto/tensors_to_face_landmarks_graph_options_pb2.py +32 -0
- mediapipe/tasks/cc/vision/face_stylizer/__init__.py +0 -0
- mediapipe/tasks/cc/vision/face_stylizer/calculators/__init__.py +0 -0
- mediapipe/tasks/cc/vision/face_stylizer/calculators/tensors_to_image_calculator_pb2.py +36 -0
- mediapipe/tasks/cc/vision/face_stylizer/proto/__init__.py +0 -0
- mediapipe/tasks/cc/vision/face_stylizer/proto/face_stylizer_graph_options_pb2.py +35 -0
- mediapipe/tasks/cc/vision/gesture_recognizer/__init__.py +0 -0
- mediapipe/tasks/cc/vision/gesture_recognizer/calculators/__init__.py +0 -0
- mediapipe/tasks/cc/vision/gesture_recognizer/calculators/combined_prediction_calculator_pb2.py +33 -0
- mediapipe/tasks/cc/vision/gesture_recognizer/calculators/landmarks_to_matrix_calculator_pb2.py +31 -0
- mediapipe/tasks/cc/vision/gesture_recognizer/proto/__init__.py +0 -0
- mediapipe/tasks/cc/vision/gesture_recognizer/proto/gesture_classifier_graph_options_pb2.py +35 -0
- mediapipe/tasks/cc/vision/gesture_recognizer/proto/gesture_embedder_graph_options_pb2.py +34 -0
- mediapipe/tasks/cc/vision/gesture_recognizer/proto/gesture_recognizer_graph_options_pb2.py +36 -0
- mediapipe/tasks/cc/vision/gesture_recognizer/proto/hand_gesture_recognizer_graph_options_pb2.py +36 -0
- mediapipe/tasks/cc/vision/hand_detector/__init__.py +0 -0
- mediapipe/tasks/cc/vision/hand_detector/proto/__init__.py +0 -0
- mediapipe/tasks/cc/vision/hand_detector/proto/hand_detector_graph_options_pb2.py +34 -0
- mediapipe/tasks/cc/vision/hand_detector/proto/hand_detector_result_pb2.py +30 -0
- mediapipe/tasks/cc/vision/hand_landmarker/__init__.py +0 -0
- mediapipe/tasks/cc/vision/hand_landmarker/calculators/__init__.py +0 -0
- mediapipe/tasks/cc/vision/hand_landmarker/calculators/hand_association_calculator_pb2.py +31 -0
- mediapipe/tasks/cc/vision/hand_landmarker/proto/__init__.py +0 -0
- mediapipe/tasks/cc/vision/hand_landmarker/proto/hand_landmarker_graph_options_pb2.py +36 -0
- mediapipe/tasks/cc/vision/hand_landmarker/proto/hand_landmarks_detector_graph_options_pb2.py +34 -0
- mediapipe/tasks/cc/vision/hand_landmarker/proto/hand_roi_refinement_graph_options_pb2.py +28 -0
- mediapipe/tasks/cc/vision/holistic_landmarker/__init__.py +0 -0
- mediapipe/tasks/cc/vision/holistic_landmarker/proto/__init__.py +0 -0
- mediapipe/tasks/cc/vision/holistic_landmarker/proto/holistic_landmarker_graph_options_pb2.py +34 -0
- mediapipe/tasks/cc/vision/holistic_landmarker/proto/holistic_result_pb2.py +29 -0
- mediapipe/tasks/cc/vision/image_classifier/__init__.py +0 -0
- mediapipe/tasks/cc/vision/image_classifier/proto/__init__.py +0 -0
- mediapipe/tasks/cc/vision/image_classifier/proto/image_classifier_graph_options_pb2.py +35 -0
- mediapipe/tasks/cc/vision/image_embedder/__init__.py +0 -0
- mediapipe/tasks/cc/vision/image_embedder/proto/__init__.py +0 -0
- mediapipe/tasks/cc/vision/image_embedder/proto/image_embedder_graph_options_pb2.py +35 -0
- mediapipe/tasks/cc/vision/image_generator/__init__.py +0 -0
- mediapipe/tasks/cc/vision/image_generator/diffuser/__init__.py +0 -0
- mediapipe/tasks/cc/vision/image_generator/diffuser/stable_diffusion_iterate_calculator_pb2.py +40 -0
- mediapipe/tasks/cc/vision/image_generator/proto/__init__.py +0 -0
- mediapipe/tasks/cc/vision/image_generator/proto/conditioned_image_graph_options_pb2.py +40 -0
- mediapipe/tasks/cc/vision/image_generator/proto/control_plugin_graph_options_pb2.py +34 -0
- mediapipe/tasks/cc/vision/image_generator/proto/image_generator_graph_options_pb2.py +30 -0
- mediapipe/tasks/cc/vision/image_segmenter/__init__.py +0 -0
- mediapipe/tasks/cc/vision/image_segmenter/calculators/__init__.py +0 -0
- mediapipe/tasks/cc/vision/image_segmenter/calculators/tensors_to_segmentation_calculator_pb2.py +34 -0
- mediapipe/tasks/cc/vision/image_segmenter/proto/__init__.py +0 -0
- mediapipe/tasks/cc/vision/image_segmenter/proto/image_segmenter_graph_options_pb2.py +35 -0
- mediapipe/tasks/cc/vision/image_segmenter/proto/segmenter_options_pb2.py +33 -0
- mediapipe/tasks/cc/vision/interactive_segmenter/__init__.py +0 -0
- mediapipe/tasks/cc/vision/object_detector/__init__.py +0 -0
- mediapipe/tasks/cc/vision/object_detector/proto/__init__.py +0 -0
- mediapipe/tasks/cc/vision/object_detector/proto/object_detector_options_pb2.py +34 -0
- mediapipe/tasks/cc/vision/pose_detector/__init__.py +0 -0
- mediapipe/tasks/cc/vision/pose_detector/proto/__init__.py +0 -0
- mediapipe/tasks/cc/vision/pose_detector/proto/pose_detector_graph_options_pb2.py +34 -0
- mediapipe/tasks/cc/vision/pose_landmarker/__init__.py +0 -0
- mediapipe/tasks/cc/vision/pose_landmarker/proto/__init__.py +0 -0
- mediapipe/tasks/cc/vision/pose_landmarker/proto/pose_landmarker_graph_options_pb2.py +36 -0
- mediapipe/tasks/cc/vision/pose_landmarker/proto/pose_landmarks_detector_graph_options_pb2.py +34 -0
- mediapipe/tasks/cc/vision/utils/__init__.py +0 -0
- mediapipe/tasks/cc/vision/utils/ghum/__init__.py +0 -0
- mediapipe/tasks/metadata/image_segmenter_metadata_schema.fbs +59 -0
- mediapipe/tasks/metadata/image_segmenter_metadata_schema_py_generated.py +108 -0
- mediapipe/tasks/metadata/metadata_schema.fbs +732 -0
- mediapipe/tasks/metadata/metadata_schema_py_generated.py +3251 -0
- mediapipe/tasks/metadata/object_detector_metadata_schema.fbs +98 -0
- mediapipe/tasks/metadata/object_detector_metadata_schema_py_generated.py +674 -0
- mediapipe/tasks/metadata/schema_py_generated.py +18438 -0
- mediapipe/tasks/python/__init__.py +27 -0
- mediapipe/tasks/python/audio/__init__.py +33 -0
- mediapipe/tasks/python/audio/audio_classifier.py +324 -0
- mediapipe/tasks/python/audio/audio_embedder.py +285 -0
- mediapipe/tasks/python/audio/core/__init__.py +16 -0
- mediapipe/tasks/python/audio/core/audio_record.py +125 -0
- mediapipe/tasks/python/audio/core/audio_task_running_mode.py +29 -0
- mediapipe/tasks/python/audio/core/base_audio_task_api.py +181 -0
- mediapipe/tasks/python/benchmark/__init__.py +13 -0
- mediapipe/tasks/python/benchmark/benchmark_utils.py +70 -0
- mediapipe/tasks/python/benchmark/vision/__init__.py +13 -0
- mediapipe/tasks/python/benchmark/vision/benchmark.py +99 -0
- mediapipe/tasks/python/benchmark/vision/core/__init__.py +14 -0
- mediapipe/tasks/python/benchmark/vision/core/base_vision_benchmark_api.py +40 -0
- mediapipe/tasks/python/components/__init__.py +13 -0
- mediapipe/tasks/python/components/containers/__init__.py +53 -0
- mediapipe/tasks/python/components/containers/audio_data.py +137 -0
- mediapipe/tasks/python/components/containers/bounding_box.py +73 -0
- mediapipe/tasks/python/components/containers/category.py +78 -0
- mediapipe/tasks/python/components/containers/classification_result.py +111 -0
- mediapipe/tasks/python/components/containers/detections.py +181 -0
- mediapipe/tasks/python/components/containers/embedding_result.py +89 -0
- mediapipe/tasks/python/components/containers/keypoint.py +77 -0
- mediapipe/tasks/python/components/containers/landmark.py +122 -0
- mediapipe/tasks/python/components/containers/landmark_detection_result.py +106 -0
- mediapipe/tasks/python/components/containers/rect.py +109 -0
- mediapipe/tasks/python/components/processors/__init__.py +23 -0
- mediapipe/tasks/python/components/processors/classifier_options.py +86 -0
- mediapipe/tasks/python/components/utils/__init__.py +13 -0
- mediapipe/tasks/python/components/utils/cosine_similarity.py +68 -0
- mediapipe/tasks/python/core/__init__.py +13 -0
- mediapipe/tasks/python/core/base_options.py +121 -0
- mediapipe/tasks/python/core/optional_dependencies.py +25 -0
- mediapipe/tasks/python/core/task_info.py +139 -0
- mediapipe/tasks/python/genai/__init__.py +14 -0
- mediapipe/tasks/python/genai/bundler/__init__.py +23 -0
- mediapipe/tasks/python/genai/bundler/llm_bundler.py +130 -0
- mediapipe/tasks/python/genai/bundler/llm_bundler_test.py +168 -0
- mediapipe/tasks/python/genai/converter/__init__.py +24 -0
- mediapipe/tasks/python/genai/converter/converter_base.py +179 -0
- mediapipe/tasks/python/genai/converter/converter_factory.py +79 -0
- mediapipe/tasks/python/genai/converter/llm_converter.py +374 -0
- mediapipe/tasks/python/genai/converter/llm_converter_test.py +63 -0
- mediapipe/tasks/python/genai/converter/pytorch_converter.py +318 -0
- mediapipe/tasks/python/genai/converter/pytorch_converter_test.py +86 -0
- mediapipe/tasks/python/genai/converter/quantization_util.py +516 -0
- mediapipe/tasks/python/genai/converter/quantization_util_test.py +259 -0
- mediapipe/tasks/python/genai/converter/safetensors_converter.py +580 -0
- mediapipe/tasks/python/genai/converter/safetensors_converter_test.py +83 -0
- mediapipe/tasks/python/genai/converter/weight_bins_writer.py +120 -0
- mediapipe/tasks/python/genai/converter/weight_bins_writer_test.py +95 -0
- mediapipe/tasks/python/metadata/__init__.py +13 -0
- mediapipe/tasks/python/metadata/flatbuffers_lib/_pywrap_flatbuffers.cpython-310-x86_64-linux-gnu.so +0 -0
- mediapipe/tasks/python/metadata/metadata.py +928 -0
- mediapipe/tasks/python/metadata/metadata_displayer_cli.py +34 -0
- mediapipe/tasks/python/metadata/metadata_writers/__init__.py +13 -0
- mediapipe/tasks/python/metadata/metadata_writers/face_stylizer.py +138 -0
- mediapipe/tasks/python/metadata/metadata_writers/image_classifier.py +71 -0
- mediapipe/tasks/python/metadata/metadata_writers/image_segmenter.py +170 -0
- mediapipe/tasks/python/metadata/metadata_writers/metadata_info.py +1166 -0
- mediapipe/tasks/python/metadata/metadata_writers/metadata_writer.py +845 -0
- mediapipe/tasks/python/metadata/metadata_writers/model_asset_bundle_utils.py +71 -0
- mediapipe/tasks/python/metadata/metadata_writers/object_detector.py +331 -0
- mediapipe/tasks/python/metadata/metadata_writers/text_classifier.py +119 -0
- mediapipe/tasks/python/metadata/metadata_writers/writer_utils.py +91 -0
- mediapipe/tasks/python/test/__init__.py +13 -0
- mediapipe/tasks/python/test/audio/__init__.py +13 -0
- mediapipe/tasks/python/test/audio/audio_classifier_test.py +387 -0
- mediapipe/tasks/python/test/audio/audio_embedder_test.py +297 -0
- mediapipe/tasks/python/test/test_utils.py +196 -0
- mediapipe/tasks/python/test/text/__init__.py +13 -0
- mediapipe/tasks/python/test/text/language_detector_test.py +228 -0
- mediapipe/tasks/python/test/text/text_classifier_test.py +235 -0
- mediapipe/tasks/python/test/text/text_embedder_test.py +326 -0
- mediapipe/tasks/python/test/vision/__init__.py +13 -0
- mediapipe/tasks/python/test/vision/face_aligner_test.py +190 -0
- mediapipe/tasks/python/test/vision/face_detector_test.py +523 -0
- mediapipe/tasks/python/test/vision/face_landmarker_test.py +565 -0
- mediapipe/tasks/python/test/vision/face_stylizer_test.py +191 -0
- mediapipe/tasks/python/test/vision/hand_landmarker_test.py +437 -0
- mediapipe/tasks/python/test/vision/holistic_landmarker_test.py +544 -0
- mediapipe/tasks/python/test/vision/image_classifier_test.py +657 -0
- mediapipe/tasks/python/test/vision/image_embedder_test.py +423 -0
- mediapipe/tasks/python/test/vision/image_segmenter_test.py +512 -0
- mediapipe/tasks/python/test/vision/interactive_segmenter_test.py +341 -0
- mediapipe/tasks/python/test/vision/object_detector_test.py +493 -0
- mediapipe/tasks/python/test/vision/pose_landmarker_test.py +518 -0
- mediapipe/tasks/python/text/__init__.py +35 -0
- mediapipe/tasks/python/text/core/__init__.py +16 -0
- mediapipe/tasks/python/text/core/base_text_task_api.py +54 -0
- mediapipe/tasks/python/text/language_detector.py +220 -0
- mediapipe/tasks/python/text/text_classifier.py +187 -0
- mediapipe/tasks/python/text/text_embedder.py +188 -0
- mediapipe/tasks/python/vision/__init__.py +90 -0
- mediapipe/tasks/python/vision/core/__init__.py +14 -0
- mediapipe/tasks/python/vision/core/base_vision_task_api.py +226 -0
- mediapipe/tasks/python/vision/core/image_processing_options.py +39 -0
- mediapipe/tasks/python/vision/core/vision_task_running_mode.py +31 -0
- mediapipe/tasks/python/vision/face_aligner.py +158 -0
- mediapipe/tasks/python/vision/face_detector.py +332 -0
- mediapipe/tasks/python/vision/face_landmarker.py +3244 -0
- mediapipe/tasks/python/vision/face_stylizer.py +158 -0
- mediapipe/tasks/python/vision/gesture_recognizer.py +480 -0
- mediapipe/tasks/python/vision/hand_landmarker.py +504 -0
- mediapipe/tasks/python/vision/holistic_landmarker.py +576 -0
- mediapipe/tasks/python/vision/image_classifier.py +358 -0
- mediapipe/tasks/python/vision/image_embedder.py +362 -0
- mediapipe/tasks/python/vision/image_segmenter.py +433 -0
- mediapipe/tasks/python/vision/interactive_segmenter.py +285 -0
- mediapipe/tasks/python/vision/object_detector.py +389 -0
- mediapipe/tasks/python/vision/pose_landmarker.py +455 -0
- mediapipe/util/__init__.py +0 -0
- mediapipe/util/analytics/__init__.py +0 -0
- mediapipe/util/analytics/mediapipe_log_extension_pb2.py +44 -0
- mediapipe/util/analytics/mediapipe_logging_enums_pb2.py +37 -0
- mediapipe/util/audio_decoder_pb2.py +33 -0
- mediapipe/util/color_pb2.py +33 -0
- mediapipe/util/label_map_pb2.py +27 -0
- mediapipe/util/render_data_pb2.py +58 -0
- mediapipe/util/sequence/__init__.py +14 -0
- mediapipe/util/sequence/media_sequence.py +716 -0
- mediapipe/util/sequence/media_sequence_test.py +290 -0
- mediapipe/util/sequence/media_sequence_util.py +800 -0
- mediapipe/util/sequence/media_sequence_util_test.py +389 -0
- mediapipe/util/tracking/__init__.py +0 -0
- mediapipe/util/tracking/box_detector_pb2.py +39 -0
- mediapipe/util/tracking/box_tracker_pb2.py +32 -0
- mediapipe/util/tracking/camera_motion_pb2.py +31 -0
- mediapipe/util/tracking/flow_packager_pb2.py +60 -0
- mediapipe/util/tracking/frame_selection_pb2.py +35 -0
- mediapipe/util/tracking/frame_selection_solution_evaluator_pb2.py +28 -0
- mediapipe/util/tracking/motion_analysis_pb2.py +35 -0
- mediapipe/util/tracking/motion_estimation_pb2.py +66 -0
- mediapipe/util/tracking/motion_models_pb2.py +42 -0
- mediapipe/util/tracking/motion_saliency_pb2.py +26 -0
- mediapipe/util/tracking/push_pull_filtering_pb2.py +26 -0
- mediapipe/util/tracking/region_flow_computation_pb2.py +59 -0
- mediapipe/util/tracking/region_flow_pb2.py +49 -0
- mediapipe/util/tracking/tone_estimation_pb2.py +45 -0
- mediapipe/util/tracking/tone_models_pb2.py +32 -0
- mediapipe/util/tracking/tracked_detection_manager_config_pb2.py +26 -0
- mediapipe/util/tracking/tracking_pb2.py +73 -0
- mediapipe_nightly-0.10.21.post20250114.dist-info/LICENSE +218 -0
- mediapipe_nightly-0.10.21.post20250114.dist-info/METADATA +199 -0
- mediapipe_nightly-0.10.21.post20250114.dist-info/RECORD +593 -0
- mediapipe_nightly-0.10.21.post20250114.dist-info/WHEEL +5 -0
- mediapipe_nightly-0.10.21.post20250114.dist-info/top_level.txt +4 -0
- mediapipe_nightly.libs/libEGL-48f73270.so.1.1.0 +0 -0
- mediapipe_nightly.libs/libGLESv2-ed5eda4f.so.2.1.0 +0 -0
- mediapipe_nightly.libs/libGLdispatch-64b28464.so.0.0.0 +0 -0
@@ -0,0 +1,580 @@
|
|
1
|
+
# Copyright 2024 The MediaPipe Authors.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
"""CkptLoader implementation for loading the Safetensors."""
|
16
|
+
|
17
|
+
import array
|
18
|
+
from typing import Iterator
|
19
|
+
import enum
|
20
|
+
import glob
|
21
|
+
import json
|
22
|
+
import os
|
23
|
+
from typing import List, Optional
|
24
|
+
|
25
|
+
import numpy as np
|
26
|
+
import torch
|
27
|
+
|
28
|
+
from mediapipe.tasks.python.genai.converter import converter_base
|
29
|
+
|
30
|
+
|
31
|
+
DTYPE_MAP = {
|
32
|
+
"F16": torch.float16,
|
33
|
+
"BF16": torch.bfloat16,
|
34
|
+
"F32": torch.float32,
|
35
|
+
}
|
36
|
+
|
37
|
+
|
38
|
+
class _SafetensorsShardReader:
|
39
|
+
"""Reads a single safetensors shard."""
|
40
|
+
|
41
|
+
_HEAD_BYTES = 8
|
42
|
+
|
43
|
+
def __init__(self, shard_path: str):
|
44
|
+
self._shard_path = shard_path
|
45
|
+
if not os.path.exists(self._shard_path):
|
46
|
+
raise ValueError(f"{self._shard_path} does not exists.")
|
47
|
+
with open(self._shard_path, "rb") as f:
|
48
|
+
head_bytes = f.read(self._HEAD_BYTES)
|
49
|
+
metadata_bytes_num = np.frombuffer(head_bytes, dtype=np.uint64)[0]
|
50
|
+
metadata_bytes = f.read(metadata_bytes_num)
|
51
|
+
self.layers_info = json.loads(metadata_bytes)
|
52
|
+
self.metadata_bytes_num = metadata_bytes_num
|
53
|
+
|
54
|
+
def read_tensor_as_numpy(self, tensor_name) -> np.ndarray:
|
55
|
+
"""Reads a tensor from the model file as a numpy array with np.float32 type."""
|
56
|
+
tensor_info = self.layers_info[tensor_name]
|
57
|
+
with open(self._shard_path, "rb") as f:
|
58
|
+
shape = tensor_info["shape"]
|
59
|
+
dtype = tensor_info["dtype"]
|
60
|
+
if dtype not in DTYPE_MAP:
|
61
|
+
raise ValueError(f"{dtype} is not supported.")
|
62
|
+
data_offsets = tensor_info["data_offsets"]
|
63
|
+
f.seek(int(self._HEAD_BYTES + self.metadata_bytes_num + data_offsets[0]))
|
64
|
+
tensor_bytes = f.read(data_offsets[1] - data_offsets[0])
|
65
|
+
raw_tensor = torch.frombuffer(
|
66
|
+
array.array("b", tensor_bytes), dtype=DTYPE_MAP[dtype]
|
67
|
+
).reshape(shape)
|
68
|
+
return raw_tensor.float().t().contiguous().numpy()
|
69
|
+
|
70
|
+
def get_tensor_names(self) -> List[str]:
|
71
|
+
names = list(self.layers_info.keys())
|
72
|
+
if "__metadata__" in names:
|
73
|
+
names.remove("__metadata__")
|
74
|
+
return names
|
75
|
+
|
76
|
+
|
77
|
+
class _SafetensorsReader:
|
78
|
+
"""Reads all the safetensors shards."""
|
79
|
+
|
80
|
+
def __init__(self, ckpt_path: str):
|
81
|
+
shards = []
|
82
|
+
if os.path.isdir(ckpt_path):
|
83
|
+
# Read all safetensors files within checkpoint
|
84
|
+
for shard_path in glob.glob(os.path.join(ckpt_path, "*.safetensors")):
|
85
|
+
shards.append(_SafetensorsShardReader(shard_path))
|
86
|
+
else:
|
87
|
+
# Assume the ckpt_path is a file or a file pattern to match.
|
88
|
+
for shard_path in glob.glob(ckpt_path):
|
89
|
+
shards.append(_SafetensorsShardReader(shard_path))
|
90
|
+
assert shards is not None
|
91
|
+
|
92
|
+
self._ckpt_path = ckpt_path
|
93
|
+
self._tensors_map = {}
|
94
|
+
for shard in shards:
|
95
|
+
tensor_names = shard.get_tensor_names()
|
96
|
+
for tensor_name in tensor_names:
|
97
|
+
if tensor_name in self._tensors_map:
|
98
|
+
raise ValueError(f"Duplicate tensor name: {tensor_name}")
|
99
|
+
self._tensors_map[tensor_name] = shard
|
100
|
+
|
101
|
+
def get_tensor_names(self) -> List[str]:
|
102
|
+
return list(self._tensors_map.keys())
|
103
|
+
|
104
|
+
def read_tensor_as_numpy(self, tensor_name: str) -> np.ndarray:
|
105
|
+
return self._tensors_map[tensor_name].read_tensor_as_numpy(tensor_name)
|
106
|
+
|
107
|
+
|
108
|
+
class LayerType(enum.Enum):
|
109
|
+
"""Enum for layer type."""
|
110
|
+
|
111
|
+
NONE = 0
|
112
|
+
ATTENTION = 1 # Layer is part of the attention module.
|
113
|
+
FEEDFORWARD = 2 # Layer is part of the feedforward module in the Transformer.
|
114
|
+
EMBEDDING = 3 # Layer is the embedding lookup or final projection layer.
|
115
|
+
LAYER_NORM = (
|
116
|
+
4 # Layer is layer normalization before and after attention layer.
|
117
|
+
)
|
118
|
+
LORA = 5 # Layer is LoRA weights augmented on the base model layers.
|
119
|
+
|
120
|
+
@classmethod
|
121
|
+
def get_layer_type(cls, layer_name: str):
|
122
|
+
"""Gets the layer type of the given layer name."""
|
123
|
+
ffn_layers = [
|
124
|
+
"mlp",
|
125
|
+
]
|
126
|
+
attn_layers = [
|
127
|
+
"self_attn",
|
128
|
+
]
|
129
|
+
emb_layers = [
|
130
|
+
"embed_tokens",
|
131
|
+
"lm_head",
|
132
|
+
]
|
133
|
+
layer_norms = [
|
134
|
+
"input_layernorm",
|
135
|
+
"post_attention_layernorm",
|
136
|
+
"final_layernorm",
|
137
|
+
"model.norm.weight",
|
138
|
+
"pre_feedforward_layernorm",
|
139
|
+
"post_feedforward_layernorm",
|
140
|
+
]
|
141
|
+
lora_layers = ["lora"]
|
142
|
+
if any(sub_name in layer_name for sub_name in lora_layers):
|
143
|
+
return LayerType.LORA
|
144
|
+
if any(sub_name in layer_name for sub_name in attn_layers):
|
145
|
+
return LayerType.ATTENTION
|
146
|
+
if any(sub_name in layer_name for sub_name in ffn_layers):
|
147
|
+
return LayerType.FEEDFORWARD
|
148
|
+
if any(sub_name in layer_name for sub_name in emb_layers):
|
149
|
+
return LayerType.EMBEDDING
|
150
|
+
if any(sub_name in layer_name for sub_name in layer_norms):
|
151
|
+
return LayerType.LAYER_NORM
|
152
|
+
else:
|
153
|
+
return LayerType.NONE
|
154
|
+
|
155
|
+
|
156
|
+
class StablelmMapper(converter_base.LayerActionMapperBase):
|
157
|
+
"""LayerActionMapper for handling the StableLM model."""
|
158
|
+
|
159
|
+
def __init__(
|
160
|
+
self,
|
161
|
+
is_symmetric: bool,
|
162
|
+
attention_quant_bits: int,
|
163
|
+
feedforward_quant_bits: int,
|
164
|
+
embedding_quant_bits: int,
|
165
|
+
backend: str,
|
166
|
+
reader: _SafetensorsReader,
|
167
|
+
):
|
168
|
+
super().__init__(
|
169
|
+
is_symmetric=is_symmetric,
|
170
|
+
attention_quant_bits=attention_quant_bits,
|
171
|
+
feedforward_quant_bits=feedforward_quant_bits,
|
172
|
+
embedding_quant_bits=embedding_quant_bits,
|
173
|
+
backend=backend,
|
174
|
+
)
|
175
|
+
self._reader = reader
|
176
|
+
|
177
|
+
def map_to_actions(
|
178
|
+
self, layer_name: str
|
179
|
+
) -> Optional[List[converter_base.QuantizationAction]]:
|
180
|
+
"""Map the given layer name to actions."""
|
181
|
+
tensor_value = self._reader.read_tensor_as_numpy(layer_name)
|
182
|
+
quantize_axis = None
|
183
|
+
quantize_bits = None
|
184
|
+
layer_type = LayerType.get_layer_type(layer_name)
|
185
|
+
|
186
|
+
if layer_type != LayerType.LAYER_NORM and layer_name.endswith(".weight"):
|
187
|
+
quantize_axis = [0]
|
188
|
+
if layer_type == LayerType.FEEDFORWARD:
|
189
|
+
quantize_bits = self._feedforward_quant_bits
|
190
|
+
elif layer_type == LayerType.ATTENTION:
|
191
|
+
quantize_bits = self._attention_quant_bits
|
192
|
+
if self._backend == "cpu" and ".o_proj." in layer_name:
|
193
|
+
tensor_value = np.transpose(tensor_value)
|
194
|
+
quantize_axis = [1]
|
195
|
+
elif layer_type == LayerType.EMBEDDING:
|
196
|
+
quantize_bits = self._embedding_quant_bits
|
197
|
+
if self._backend == "cpu" and ".embed_tokens." in layer_name:
|
198
|
+
tensor_value = np.transpose(tensor_value)
|
199
|
+
quantize_axis = [1]
|
200
|
+
target_name = self.update_target_name(layer_name)
|
201
|
+
|
202
|
+
actions = [
|
203
|
+
converter_base.QuantizationAction(
|
204
|
+
tensor_name=layer_name,
|
205
|
+
tensor_value=tensor_value,
|
206
|
+
target_name=target_name,
|
207
|
+
quantize_axis=quantize_axis,
|
208
|
+
quantize_bits=quantize_bits,
|
209
|
+
pack_dim=0,
|
210
|
+
)
|
211
|
+
]
|
212
|
+
return actions
|
213
|
+
|
214
|
+
def update_target_name(self, target_name: str) -> str:
|
215
|
+
"""Updates the target name to match the tensor name convention."""
|
216
|
+
target_name = target_name.replace(
|
217
|
+
"model.layers.", "params.lm.transformer.x_layers_"
|
218
|
+
)
|
219
|
+
target_name = target_name.replace("mlp.up_proj", "ff_layer.ffn_layer1")
|
220
|
+
target_name = target_name.replace("mlp.down_proj", "ff_layer.ffn_layer2")
|
221
|
+
target_name = target_name.replace(
|
222
|
+
"mlp.gate_proj", "ff_layer.ffn_layer1_gate"
|
223
|
+
)
|
224
|
+
target_name = target_name.replace("input_layernorm", "pre_layer_norm")
|
225
|
+
target_name = target_name.replace(
|
226
|
+
"pre_layer_norm.weight", "pre_layer_norm.scale"
|
227
|
+
)
|
228
|
+
if self._backend == "cpu":
|
229
|
+
target_name = target_name.replace(
|
230
|
+
"post_attention_layernorm", "ff_layer.pre_layer_norm"
|
231
|
+
)
|
232
|
+
target_name = target_name.replace(
|
233
|
+
"ff_layer.pre_layer_norm.weight", "ff_layer.pre_layer_norm.scale"
|
234
|
+
)
|
235
|
+
else:
|
236
|
+
target_name = target_name.replace(
|
237
|
+
"post_attention_layernorm", "post_layer_norm"
|
238
|
+
)
|
239
|
+
target_name = target_name.replace(
|
240
|
+
"post_layer_norm.weight", "post_layer_norm.scale"
|
241
|
+
)
|
242
|
+
target_name = target_name.replace("self_attn.q_proj", "self_attention.q")
|
243
|
+
target_name = target_name.replace("self_attn.k_proj", "self_attention.k")
|
244
|
+
target_name = target_name.replace("self_attn.v_proj", "self_attention.v")
|
245
|
+
target_name = target_name.replace("self_attn.o_proj", "self_attention.post")
|
246
|
+
target_name = target_name.replace(
|
247
|
+
"model.embed_tokens", "params.lm.token_embedding"
|
248
|
+
)
|
249
|
+
target_name = target_name.replace("model.norm", "params.lm.final_ln")
|
250
|
+
target_name = target_name.replace("final_ln.weight", "final_ln.scale")
|
251
|
+
target_name = target_name.replace("lm_head", "params.lm.softmax.logits_ffn")
|
252
|
+
target_name = target_name.replace(".weight", ".w")
|
253
|
+
|
254
|
+
return target_name
|
255
|
+
|
256
|
+
|
257
|
+
class PhiMapper(converter_base.LayerActionMapperBase):
|
258
|
+
"""LayerActionMapper for handling the Phi model."""
|
259
|
+
|
260
|
+
def __init__(
|
261
|
+
self,
|
262
|
+
is_symmetric: bool,
|
263
|
+
attention_quant_bits: int,
|
264
|
+
feedforward_quant_bits: int,
|
265
|
+
embedding_quant_bits: int,
|
266
|
+
backend: str,
|
267
|
+
reader: _SafetensorsReader,
|
268
|
+
):
|
269
|
+
super().__init__(
|
270
|
+
is_symmetric=is_symmetric,
|
271
|
+
attention_quant_bits=attention_quant_bits,
|
272
|
+
feedforward_quant_bits=feedforward_quant_bits,
|
273
|
+
embedding_quant_bits=embedding_quant_bits,
|
274
|
+
backend=backend,
|
275
|
+
)
|
276
|
+
self._reader = reader
|
277
|
+
|
278
|
+
def map_to_actions(
|
279
|
+
self, layer_name: str
|
280
|
+
) -> Optional[List[converter_base.QuantizationAction]]:
|
281
|
+
"""Map the given layer name to actions."""
|
282
|
+
tensor_value = self._reader.read_tensor_as_numpy(layer_name)
|
283
|
+
quantize_axis = None
|
284
|
+
quantize_bits = None
|
285
|
+
layer_type = LayerType.get_layer_type(layer_name)
|
286
|
+
|
287
|
+
if (
|
288
|
+
layer_type != LayerType.LAYER_NORM
|
289
|
+
and layer_name.endswith(".weight")
|
290
|
+
and layer_type != LayerType.LORA
|
291
|
+
):
|
292
|
+
quantize_axis = [0]
|
293
|
+
if layer_type == LayerType.FEEDFORWARD:
|
294
|
+
quantize_bits = self._feedforward_quant_bits
|
295
|
+
elif layer_type == LayerType.ATTENTION:
|
296
|
+
quantize_bits = self._attention_quant_bits
|
297
|
+
if self._backend == "cpu" and ".dense." in layer_name:
|
298
|
+
tensor_value = np.transpose(tensor_value)
|
299
|
+
quantize_axis = [1]
|
300
|
+
elif layer_type == LayerType.EMBEDDING:
|
301
|
+
quantize_bits = self._embedding_quant_bits
|
302
|
+
if self._backend == "cpu" and ".embed_tokens." in layer_name:
|
303
|
+
tensor_value = np.transpose(tensor_value)
|
304
|
+
quantize_axis = [1]
|
305
|
+
target_name = self.update_target_name(layer_name)
|
306
|
+
|
307
|
+
actions = [
|
308
|
+
converter_base.QuantizationAction(
|
309
|
+
tensor_name=layer_name,
|
310
|
+
tensor_value=tensor_value,
|
311
|
+
target_name=target_name,
|
312
|
+
quantize_axis=quantize_axis,
|
313
|
+
quantize_bits=quantize_bits,
|
314
|
+
pack_dim=0,
|
315
|
+
)
|
316
|
+
]
|
317
|
+
return actions
|
318
|
+
|
319
|
+
def update_target_name(self, target_name: str) -> str:
|
320
|
+
"""Updates the target name to match the tensor name convention."""
|
321
|
+
target_name = target_name.replace("base_model.model.", "")
|
322
|
+
target_name = target_name.replace(
|
323
|
+
"model.layers.", "params.lm.transformer.x_layers_"
|
324
|
+
)
|
325
|
+
|
326
|
+
layer_type = LayerType.get_layer_type(target_name)
|
327
|
+
if layer_type == LayerType.FEEDFORWARD:
|
328
|
+
target_name = target_name.replace(".weight", ".linear.w")
|
329
|
+
target_name = target_name.replace(".bias", ".bias.b")
|
330
|
+
target_name = target_name.replace("mlp.fc1", "ff_layer.ffn_layer1")
|
331
|
+
target_name = target_name.replace("mlp.fc2", "ff_layer.ffn_layer2")
|
332
|
+
|
333
|
+
elif layer_type == LayerType.ATTENTION:
|
334
|
+
target_name = target_name.replace(".weight", ".linear.w")
|
335
|
+
target_name = target_name.replace(".bias", ".bias.b")
|
336
|
+
target_name = target_name.replace("self_attn.q_proj", "self_attention.q")
|
337
|
+
target_name = target_name.replace("self_attn.k_proj", "self_attention.k")
|
338
|
+
target_name = target_name.replace("self_attn.v_proj", "self_attention.v")
|
339
|
+
target_name = target_name.replace(
|
340
|
+
"self_attn.dense", "self_attention.post"
|
341
|
+
)
|
342
|
+
elif layer_type == LayerType.EMBEDDING:
|
343
|
+
target_name = target_name.replace(
|
344
|
+
"model.embed_tokens", "params.lm.token_embedding"
|
345
|
+
)
|
346
|
+
target_name = target_name.replace(
|
347
|
+
"lm_head", "params.lm.softmax.logits_ffn"
|
348
|
+
)
|
349
|
+
target_name = target_name.replace(
|
350
|
+
"logits_ffn.weight", "logits_ffn.linear.w"
|
351
|
+
)
|
352
|
+
target_name = target_name.replace("logits_ffn.bias", "logits_ffn.bias.b")
|
353
|
+
elif layer_type == LayerType.LAYER_NORM:
|
354
|
+
target_name = target_name.replace("input_layernorm", "pre_layer_norm")
|
355
|
+
target_name = target_name.replace(
|
356
|
+
"pre_layer_norm.weight", "pre_layer_norm.scale"
|
357
|
+
)
|
358
|
+
target_name = target_name.replace(
|
359
|
+
"model.final_layernorm", "params.lm.final_ln"
|
360
|
+
)
|
361
|
+
target_name = target_name.replace("final_ln.weight", "final_ln.scale")
|
362
|
+
target_name = target_name.replace(".weight", ".w")
|
363
|
+
|
364
|
+
# For LoRA weights
|
365
|
+
if "post" in target_name:
|
366
|
+
target_name = target_name.replace("lora_A.linear.w", "w_prime_right")
|
367
|
+
target_name = target_name.replace("lora_B.linear.w", "w_prime_left")
|
368
|
+
else:
|
369
|
+
target_name = target_name.replace("lora_A.linear.w", "w_prime_left")
|
370
|
+
target_name = target_name.replace("lora_B.linear.w", "w_prime_right")
|
371
|
+
|
372
|
+
return target_name
|
373
|
+
|
374
|
+
|
375
|
+
class GemmaMapper(converter_base.LayerActionMapperBase):
|
376
|
+
"""LayerActionMapper for handling the Gemma model."""
|
377
|
+
|
378
|
+
def __init__(
|
379
|
+
self,
|
380
|
+
is_symmetric: bool,
|
381
|
+
attention_quant_bits: int,
|
382
|
+
feedforward_quant_bits: int,
|
383
|
+
embedding_quant_bits: int,
|
384
|
+
backend: str,
|
385
|
+
reader: _SafetensorsReader,
|
386
|
+
is_v2: bool,
|
387
|
+
):
|
388
|
+
super().__init__(
|
389
|
+
is_symmetric=is_symmetric,
|
390
|
+
attention_quant_bits=attention_quant_bits,
|
391
|
+
feedforward_quant_bits=feedforward_quant_bits,
|
392
|
+
embedding_quant_bits=embedding_quant_bits,
|
393
|
+
backend=backend,
|
394
|
+
)
|
395
|
+
self._reader = reader
|
396
|
+
self._is_v2 = is_v2
|
397
|
+
|
398
|
+
def map_to_actions(
|
399
|
+
self, layer_name: str
|
400
|
+
) -> Optional[List[converter_base.QuantizationAction]]:
|
401
|
+
"""Map the given layer name to actions."""
|
402
|
+
tensor_value = self._reader.read_tensor_as_numpy(layer_name)
|
403
|
+
quantize_axis = None
|
404
|
+
quantize_bits = None
|
405
|
+
layer_type = LayerType.get_layer_type(layer_name)
|
406
|
+
|
407
|
+
if (
|
408
|
+
layer_type != LayerType.LAYER_NORM
|
409
|
+
and layer_name.endswith(".weight")
|
410
|
+
and layer_type != LayerType.LORA
|
411
|
+
):
|
412
|
+
quantize_axis = [0]
|
413
|
+
if layer_type == LayerType.FEEDFORWARD:
|
414
|
+
quantize_bits = self._feedforward_quant_bits
|
415
|
+
elif layer_type == LayerType.ATTENTION:
|
416
|
+
quantize_bits = self._attention_quant_bits
|
417
|
+
if "o_proj" in layer_name:
|
418
|
+
tensor_value = np.transpose(tensor_value)
|
419
|
+
quantize_axis = [1]
|
420
|
+
elif layer_type == LayerType.EMBEDDING:
|
421
|
+
quantize_bits = self._embedding_quant_bits
|
422
|
+
|
423
|
+
target_name = self.update_target_name(layer_name)
|
424
|
+
|
425
|
+
actions = [
|
426
|
+
converter_base.QuantizationAction(
|
427
|
+
tensor_name=layer_name,
|
428
|
+
tensor_value=tensor_value,
|
429
|
+
target_name=target_name,
|
430
|
+
quantize_axis=quantize_axis,
|
431
|
+
quantize_bits=quantize_bits,
|
432
|
+
pack_dim=0,
|
433
|
+
)
|
434
|
+
]
|
435
|
+
return actions
|
436
|
+
|
437
|
+
def update_target_name(self, target_name: str) -> str:
|
438
|
+
"""Updates the target name to match the tensor name convention."""
|
439
|
+
target_name = target_name.replace("base_model.model.", "")
|
440
|
+
target_name = target_name.replace(
|
441
|
+
"model.layers.", "params.lm.transformer.x_layers_"
|
442
|
+
)
|
443
|
+
target_name = target_name.replace("mlp.up_proj", "ff_layer.ffn_layer1")
|
444
|
+
target_name = target_name.replace("mlp.down_proj", "ff_layer.ffn_layer2")
|
445
|
+
target_name = target_name.replace(
|
446
|
+
"mlp.gate_proj", "ff_layer.ffn_layer1_gate"
|
447
|
+
)
|
448
|
+
target_name = target_name.replace("input_layernorm", "pre_layer_norm")
|
449
|
+
target_name = target_name.replace(
|
450
|
+
"pre_layer_norm.weight", "pre_layer_norm.scale"
|
451
|
+
)
|
452
|
+
|
453
|
+
# Gemma and Gemma2 differ slightly in their use of the
|
454
|
+
# "post_attention_layernorm" tensor name.
|
455
|
+
if self._is_v2:
|
456
|
+
target_name = target_name.replace(
|
457
|
+
"post_attention_layernorm", "post_layer_norm"
|
458
|
+
)
|
459
|
+
else:
|
460
|
+
target_name = target_name.replace(
|
461
|
+
"post_attention_layernorm", "ff_layer.pre_layer_norm"
|
462
|
+
)
|
463
|
+
|
464
|
+
target_name = target_name.replace(
|
465
|
+
"pre_feedforward_layernorm", "ff_layer.pre_layer_norm"
|
466
|
+
)
|
467
|
+
target_name = target_name.replace(
|
468
|
+
"post_feedforward_layernorm", "ff_layer.post_layer_norm"
|
469
|
+
)
|
470
|
+
target_name = target_name.replace(
|
471
|
+
"ff_layer.pre_layer_norm.weight", "ff_layer.pre_layer_norm.scale"
|
472
|
+
)
|
473
|
+
target_name = target_name.replace(
|
474
|
+
"ff_layer.post_layer_norm.weight", "ff_layer.post_layer_norm.scale"
|
475
|
+
)
|
476
|
+
target_name = target_name.replace(
|
477
|
+
"post_layer_norm.weight", "post_layer_norm.scale"
|
478
|
+
)
|
479
|
+
target_name = target_name.replace("self_attn.q_proj", "self_attention.q")
|
480
|
+
target_name = target_name.replace("self_attn.k_proj", "self_attention.k")
|
481
|
+
target_name = target_name.replace("self_attn.v_proj", "self_attention.v")
|
482
|
+
target_name = target_name.replace("self_attn.o_proj", "self_attention.post")
|
483
|
+
target_name = target_name.replace(
|
484
|
+
"model.embed_tokens", "params.lm.softmax.logits_ffn"
|
485
|
+
)
|
486
|
+
target_name = target_name.replace("model.norm", "params.lm.final_ln")
|
487
|
+
target_name = target_name.replace("final_ln.weight", "final_ln.scale")
|
488
|
+
target_name = target_name.replace(".weight", ".w")
|
489
|
+
|
490
|
+
# For LoRA weights
|
491
|
+
if "post" in target_name:
|
492
|
+
target_name = target_name.replace("lora_A.w", "w_prime_right")
|
493
|
+
target_name = target_name.replace("lora_B.w", "w_prime_left")
|
494
|
+
else:
|
495
|
+
target_name = target_name.replace("lora_A.w", "w_prime_left")
|
496
|
+
target_name = target_name.replace("lora_B.w", "w_prime_right")
|
497
|
+
|
498
|
+
return target_name
|
499
|
+
|
500
|
+
|
501
|
+
class SafetensorsCkptLoader(converter_base.CkptLoaderBase):
|
502
|
+
"""CkptLoader implementation for loading the Safetensors."""
|
503
|
+
|
504
|
+
def __init__(
|
505
|
+
self,
|
506
|
+
ckpt_path: str,
|
507
|
+
is_symmetric: bool,
|
508
|
+
attention_quant_bits: int,
|
509
|
+
feedforward_quant_bits: int,
|
510
|
+
embedding_quant_bits: int,
|
511
|
+
special_model: str,
|
512
|
+
backend: str,
|
513
|
+
):
|
514
|
+
"""Initializes the loader.
|
515
|
+
|
516
|
+
Args:
|
517
|
+
ckpt_path: The filepath to the safetensors file.
|
518
|
+
is_symmetric: Whether to apply symmetric or asymmetric quantization.
|
519
|
+
attention_quant_bits: An integer that specify the target quantization bits
|
520
|
+
(support 8 or 4) for the attention layers.
|
521
|
+
feedforward_quant_bits: An integer that specify the target quantization
|
522
|
+
bits (support 8 or 4) for the feedforward layers in each Transformer
|
523
|
+
blocks.
|
524
|
+
embedding_quant_bits: An integer that specify the target quantization bits
|
525
|
+
(support 8 or 4) for the embedding (and the final projection) layers.
|
526
|
+
special_model: A string that indicates which input model is and whether
|
527
|
+
any special treatment is needed.
|
528
|
+
backend: A string indicating the backend used when converting this model.
|
529
|
+
Valid options are "cpu" and "gpu".
|
530
|
+
"""
|
531
|
+
super().__init__(
|
532
|
+
ckpt_path,
|
533
|
+
is_symmetric,
|
534
|
+
attention_quant_bits,
|
535
|
+
feedforward_quant_bits,
|
536
|
+
embedding_quant_bits,
|
537
|
+
)
|
538
|
+
|
539
|
+
self._special_model = special_model
|
540
|
+
self._reader = _SafetensorsReader(ckpt_path)
|
541
|
+
if special_model in ["STABLELM_4E1T_3B"]:
|
542
|
+
self.mapper = StablelmMapper(
|
543
|
+
is_symmetric,
|
544
|
+
attention_quant_bits,
|
545
|
+
feedforward_quant_bits,
|
546
|
+
embedding_quant_bits,
|
547
|
+
backend,
|
548
|
+
self._reader,
|
549
|
+
)
|
550
|
+
elif special_model in ["PHI_2"]:
|
551
|
+
self.mapper = PhiMapper(
|
552
|
+
is_symmetric,
|
553
|
+
attention_quant_bits,
|
554
|
+
feedforward_quant_bits,
|
555
|
+
embedding_quant_bits,
|
556
|
+
backend,
|
557
|
+
self._reader,
|
558
|
+
)
|
559
|
+
elif special_model in ["GEMMA_2B", "GEMMA_7B", "GEMMA2_2B"]:
|
560
|
+
self.mapper = GemmaMapper(
|
561
|
+
is_symmetric,
|
562
|
+
attention_quant_bits,
|
563
|
+
feedforward_quant_bits,
|
564
|
+
embedding_quant_bits,
|
565
|
+
backend,
|
566
|
+
self._reader,
|
567
|
+
True if special_model in ["GEMMA2_2B"] else False,
|
568
|
+
)
|
569
|
+
else:
|
570
|
+
raise ValueError(f"Unknown special model: {special_model}")
|
571
|
+
|
572
|
+
def load_to_actions(
|
573
|
+
self,
|
574
|
+
) -> Iterator[List[converter_base.QuantizationAction]]:
|
575
|
+
tensor_names = self._reader.get_tensor_names()
|
576
|
+
for tensor_name in tensor_names:
|
577
|
+
tensor_actions = self.mapper.map_to_actions(tensor_name)
|
578
|
+
if tensor_actions is None:
|
579
|
+
continue
|
580
|
+
yield tensor_actions
|
@@ -0,0 +1,83 @@
|
|
1
|
+
# Copyright 2024 The MediaPipe Authors.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
"""Unit tests for safetensors_converter."""
|
16
|
+
|
17
|
+
import os
|
18
|
+
|
19
|
+
from absl.testing import absltest
|
20
|
+
from absl.testing import parameterized
|
21
|
+
|
22
|
+
from mediapipe.tasks.python.genai.converter import safetensors_converter
|
23
|
+
from mediapipe.tasks.python.test import test_utils
|
24
|
+
|
25
|
+
_TEST_DATA_DIR = 'mediapipe/tasks/testdata/text'
|
26
|
+
_SAFETENSORS_FILE = test_utils.get_test_data_path(
|
27
|
+
os.path.join(_TEST_DATA_DIR, 'stablelm_3b_4e1t_test_weight.safetensors')
|
28
|
+
)
|
29
|
+
|
30
|
+
|
31
|
+
class SafetensorsConverterTest(parameterized.TestCase):
|
32
|
+
VARIABLE_NAMES = [
|
33
|
+
'model.embed_tokens.weight',
|
34
|
+
'model.layers.0.input_layernorm.bias',
|
35
|
+
'model.layers.0.input_layernorm.weight',
|
36
|
+
'model.layers.0.mlp.down_proj.weight',
|
37
|
+
'model.layers.0.mlp.gate_proj.weight',
|
38
|
+
'model.layers.0.mlp.up_proj.weight',
|
39
|
+
'model.layers.0.post_attention_layernorm.bias',
|
40
|
+
'model.layers.0.post_attention_layernorm.weight',
|
41
|
+
'model.layers.0.self_attn.k_proj.weight',
|
42
|
+
'model.layers.0.self_attn.o_proj.weight',
|
43
|
+
'model.layers.0.self_attn.q_proj.weight',
|
44
|
+
'model.layers.0.self_attn.v_proj.weight',
|
45
|
+
'model.norm.bias',
|
46
|
+
'model.norm.weight',
|
47
|
+
'lm_head.weight',
|
48
|
+
]
|
49
|
+
|
50
|
+
def test_init(self):
|
51
|
+
loader = safetensors_converter.SafetensorsCkptLoader(
|
52
|
+
ckpt_path=_SAFETENSORS_FILE,
|
53
|
+
is_symmetric=True,
|
54
|
+
attention_quant_bits=8,
|
55
|
+
feedforward_quant_bits=8,
|
56
|
+
embedding_quant_bits=8,
|
57
|
+
special_model='STABLELM_4E1T_3B',
|
58
|
+
backend='gpu',
|
59
|
+
)
|
60
|
+
self.assertEqual(loader._ckpt_path, _SAFETENSORS_FILE)
|
61
|
+
self.assertEqual(loader._is_symmetric, True)
|
62
|
+
self.assertEqual(loader._attention_quant_bits, 8)
|
63
|
+
self.assertEqual(loader._feedforward_quant_bits, 8)
|
64
|
+
|
65
|
+
@parameterized.product(
|
66
|
+
quant_bits=(4, 8),
|
67
|
+
)
|
68
|
+
def test_load_to_actions(self, quant_bits):
|
69
|
+
loader = safetensors_converter.SafetensorsCkptLoader(
|
70
|
+
ckpt_path=_SAFETENSORS_FILE,
|
71
|
+
is_symmetric=True,
|
72
|
+
attention_quant_bits=8,
|
73
|
+
feedforward_quant_bits=quant_bits,
|
74
|
+
embedding_quant_bits=8,
|
75
|
+
special_model='STABLELM_4E1T_3B',
|
76
|
+
backend='gpu',
|
77
|
+
)
|
78
|
+
actions = loader.load_to_actions()
|
79
|
+
self.assertLen(list(actions), 15)
|
80
|
+
|
81
|
+
|
82
|
+
if __name__ == '__main__':
|
83
|
+
absltest.main()
|