@runanywhere/core 0.17.7 → 0.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +218 -2
- package/RunAnywhereCore.podspec +1 -0
- package/android/CMakeLists.txt +24 -2
- package/android/build.gradle +61 -9
- package/android/src/main/cpp/cpp-adapter.cpp +51 -3
- package/android/src/main/include/rac/backends/rac_vlm_llamacpp.h +216 -0
- package/android/src/main/include/rac/core/capabilities/rac_lifecycle.h +3 -1
- package/android/src/main/include/rac/core/rac_core.h +11 -0
- package/android/src/main/include/rac/core/rac_types.h +8 -6
- package/android/src/main/include/rac/features/diffusion/rac_diffusion.h +22 -0
- package/android/src/main/include/rac/features/diffusion/rac_diffusion_component.h +263 -0
- package/android/src/main/include/rac/features/diffusion/rac_diffusion_model_registry.h +358 -0
- package/android/src/main/include/rac/features/diffusion/rac_diffusion_service.h +187 -0
- package/android/src/main/include/rac/features/diffusion/rac_diffusion_tokenizer.h +167 -0
- package/android/src/main/include/rac/features/diffusion/rac_diffusion_types.h +454 -0
- package/android/src/main/include/rac/features/llm/rac_tool_calling.h +373 -0
- package/android/src/main/include/rac/features/platform/rac_diffusion_platform.h +305 -0
- package/android/src/main/include/rac/features/vad/rac_vad_energy.h +1 -1
- package/android/src/main/include/rac/features/vlm/rac_vlm.h +16 -0
- package/android/src/main/include/rac/features/vlm/rac_vlm_component.h +168 -0
- package/android/src/main/include/rac/features/vlm/rac_vlm_service.h +206 -0
- package/android/src/main/include/rac/features/vlm/rac_vlm_types.h +417 -0
- package/android/src/main/include/rac/infrastructure/model_management/rac_model_registry.h +15 -0
- package/android/src/main/include/rac/infrastructure/model_management/rac_model_types.h +3 -0
- package/android/src/main/include/rac/utils/rac_image_utils.h +215 -0
- package/android/src/main/java/com/margelo/nitro/runanywhere/PlatformAdapterBridge.kt +201 -1
- package/android/src/main/jniLibs/arm64-v8a/libc++_shared.so +0 -0
- package/android/src/main/jniLibs/arm64-v8a/libomp.so +0 -0
- package/android/src/main/jniLibs/arm64-v8a/librac_commons.so +0 -0
- package/android/src/main/jniLibs/arm64-v8a/librunanywhere_jni.so +0 -0
- package/android/src/main/jniLibs/x86_64/libc++_shared.so +0 -0
- package/android/src/main/jniLibs/x86_64/libomp.so +0 -0
- package/android/src/main/jniLibs/x86_64/librac_commons.so +0 -0
- package/android/src/main/jniLibs/x86_64/librunanywhere_jni.so +0 -0
- package/cpp/HybridRunAnywhereCore.cpp +259 -160
- package/cpp/HybridRunAnywhereCore.hpp +11 -0
- package/cpp/bridges/InitBridge.cpp +234 -3
- package/cpp/bridges/PlatformDownloadBridge.h +44 -0
- package/cpp/bridges/ToolCallingBridge.cpp +188 -0
- package/cpp/bridges/ToolCallingBridge.hpp +98 -0
- package/cpp/third_party/nlohmann/json.hpp +24765 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/RACommons.h +18 -4
- package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_core.h +11 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_diffusion.h +22 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_diffusion_component.h +263 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_diffusion_model_registry.h +358 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_diffusion_platform.h +305 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_diffusion_service.h +187 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_diffusion_tokenizer.h +167 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_diffusion_types.h +454 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_endpoints.h +3 -17
- package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_image_utils.h +215 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_lifecycle.h +3 -1
- package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_model_assignment.h +4 -20
- package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_model_registry.h +15 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_model_types.h +3 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_tool_calling.h +373 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_types.h +8 -6
- package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_vad_energy.h +1 -1
- package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_vlm.h +16 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_vlm_component.h +168 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_vlm_llamacpp.h +216 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_vlm_service.h +206 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_vlm_types.h +417 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/RACommons +0 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/RACommons.h +18 -4
- package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_core.h +11 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_diffusion.h +22 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_diffusion_component.h +263 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_diffusion_model_registry.h +358 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_diffusion_platform.h +305 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_diffusion_service.h +187 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_diffusion_tokenizer.h +167 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_diffusion_types.h +454 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_endpoints.h +3 -17
- package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_image_utils.h +215 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_lifecycle.h +3 -1
- package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_model_assignment.h +4 -20
- package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_model_registry.h +15 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_model_types.h +3 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_tool_calling.h +373 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_types.h +8 -6
- package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_vad_energy.h +1 -1
- package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_vlm.h +16 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_vlm_component.h +168 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_vlm_llamacpp.h +216 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_vlm_service.h +206 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_vlm_types.h +417 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/RACommons +0 -0
- package/ios/PlatformAdapterBridge.h +24 -1
- package/ios/PlatformAdapterBridge.m +243 -0
- package/nitrogen/generated/shared/c++/HybridRunAnywhereCoreSpec.cpp +4 -0
- package/nitrogen/generated/shared/c++/HybridRunAnywhereCoreSpec.hpp +4 -0
- package/package.json +8 -4
- package/src/Foundation/Security/SecureStorageService.ts +12 -6
- package/src/Public/Extensions/RunAnywhere+Models.ts +5 -3
- package/src/Public/Extensions/RunAnywhere+STT.ts +7 -2
- package/src/Public/Extensions/RunAnywhere+ToolCalling.ts +472 -0
- package/src/Public/Extensions/index.ts +16 -0
- package/src/Public/RunAnywhere.ts +18 -0
- package/src/index.ts +0 -1
- package/src/services/Network/index.ts +0 -1
- package/src/services/index.ts +0 -1
- package/src/specs/RunAnywhereCore.nitro.ts +72 -0
- package/src/types/ToolCallingTypes.ts +198 -0
- package/src/types/index.ts +13 -0
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file rac_diffusion_tokenizer.h
|
|
3
|
+
* @brief RunAnywhere Commons - Diffusion Tokenizer Utilities
|
|
4
|
+
*
|
|
5
|
+
* Utilities for managing diffusion model tokenizer files.
|
|
6
|
+
* Apple's compiled CoreML models don't include tokenizer files (vocab.json, merges.txt),
|
|
7
|
+
* so they must be downloaded from HuggingFace.
|
|
8
|
+
*
|
|
9
|
+
* This API provides:
|
|
10
|
+
* - URL resolution for predefined tokenizer sources
|
|
11
|
+
* - Automatic download of missing tokenizer files
|
|
12
|
+
* - Support for custom tokenizer URLs
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
#ifndef RAC_DIFFUSION_TOKENIZER_H
|
|
16
|
+
#define RAC_DIFFUSION_TOKENIZER_H
|
|
17
|
+
|
|
18
|
+
#include "rac/core/rac_types.h"
|
|
19
|
+
#include "rac/features/diffusion/rac_diffusion_types.h"
|
|
20
|
+
|
|
21
|
+
#ifdef __cplusplus
|
|
22
|
+
extern "C" {
|
|
23
|
+
#endif
|
|
24
|
+
|
|
25
|
+
// =============================================================================
|
|
26
|
+
// TOKENIZER FILE NAMES
|
|
27
|
+
// =============================================================================
|
|
28
|
+
|
|
29
|
+
/** Vocabulary file name */
|
|
30
|
+
#define RAC_DIFFUSION_TOKENIZER_VOCAB_FILE "vocab.json"
|
|
31
|
+
|
|
32
|
+
/** Merge rules file name */
|
|
33
|
+
#define RAC_DIFFUSION_TOKENIZER_MERGES_FILE "merges.txt"
|
|
34
|
+
|
|
35
|
+
// =============================================================================
|
|
36
|
+
// URL RESOLUTION
|
|
37
|
+
// =============================================================================
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* @brief Get the base URL for a tokenizer source
|
|
41
|
+
*
|
|
42
|
+
* Returns the HuggingFace URL for the specified tokenizer source.
|
|
43
|
+
* For custom sources, returns the custom_base_url from config.
|
|
44
|
+
*
|
|
45
|
+
* @param source Tokenizer source preset
|
|
46
|
+
* @param custom_url Custom URL (only used when source == RAC_DIFFUSION_TOKENIZER_CUSTOM)
|
|
47
|
+
* @return Base URL string (static, do not free), or NULL if invalid
|
|
48
|
+
*
|
|
49
|
+
* @note URLs returned are HuggingFace raw file URLs (resolve/main/tokenizer)
|
|
50
|
+
*
|
|
51
|
+
* Example return values:
|
|
52
|
+
* - SD_1_5: "https://huggingface.co/runwayml/stable-diffusion-v1-5/resolve/main/tokenizer"
|
|
53
|
+
* - SD_2_X: "https://huggingface.co/stabilityai/stable-diffusion-2-1/resolve/main/tokenizer"
|
|
54
|
+
* - SDXL: "https://huggingface.co/stabilityai/stable-diffusion-xl-base-1.0/resolve/main/tokenizer"
|
|
55
|
+
* - CUSTOM: Returns custom_url parameter
|
|
56
|
+
*/
|
|
57
|
+
RAC_API const char* rac_diffusion_tokenizer_get_base_url(rac_diffusion_tokenizer_source_t source,
|
|
58
|
+
const char* custom_url);
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* @brief Get the full URL for a tokenizer file
|
|
62
|
+
*
|
|
63
|
+
* Constructs the full URL for downloading a specific tokenizer file.
|
|
64
|
+
*
|
|
65
|
+
* @param source Tokenizer source preset
|
|
66
|
+
* @param custom_url Custom URL (only used when source == RAC_DIFFUSION_TOKENIZER_CUSTOM)
|
|
67
|
+
* @param filename File name to append (e.g., "vocab.json" or "merges.txt")
|
|
68
|
+
* @param out_url Output buffer for the full URL
|
|
69
|
+
* @param out_url_size Size of output buffer
|
|
70
|
+
* @return RAC_SUCCESS or error code
|
|
71
|
+
*
|
|
72
|
+
* Example:
|
|
73
|
+
* @code
|
|
74
|
+
* char url[512];
|
|
75
|
+
* rac_diffusion_tokenizer_get_file_url(
|
|
76
|
+
* RAC_DIFFUSION_TOKENIZER_SD_1_5,
|
|
77
|
+
* NULL,
|
|
78
|
+
* "vocab.json",
|
|
79
|
+
* url,
|
|
80
|
+
* sizeof(url)
|
|
81
|
+
* );
|
|
82
|
+
* // url = "https://huggingface.co/runwayml/stable-diffusion-v1-5/resolve/main/tokenizer/vocab.json"
|
|
83
|
+
* @endcode
|
|
84
|
+
*/
|
|
85
|
+
RAC_API rac_result_t rac_diffusion_tokenizer_get_file_url(rac_diffusion_tokenizer_source_t source,
|
|
86
|
+
const char* custom_url,
|
|
87
|
+
const char* filename, char* out_url,
|
|
88
|
+
size_t out_url_size);
|
|
89
|
+
|
|
90
|
+
// =============================================================================
|
|
91
|
+
// FILE MANAGEMENT
|
|
92
|
+
// =============================================================================
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* @brief Check if tokenizer files exist in a directory
|
|
96
|
+
*
|
|
97
|
+
* @param model_dir Path to the model directory
|
|
98
|
+
* @param out_has_vocab Output: true if vocab.json exists
|
|
99
|
+
* @param out_has_merges Output: true if merges.txt exists
|
|
100
|
+
* @return RAC_SUCCESS or error code
|
|
101
|
+
*/
|
|
102
|
+
RAC_API rac_result_t rac_diffusion_tokenizer_check_files(const char* model_dir,
|
|
103
|
+
rac_bool_t* out_has_vocab,
|
|
104
|
+
rac_bool_t* out_has_merges);
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* @brief Ensure tokenizer files exist, downloading if necessary
|
|
108
|
+
*
|
|
109
|
+
* Checks for vocab.json and merges.txt in the model directory.
|
|
110
|
+
* If missing and auto_download is enabled, downloads from the configured source.
|
|
111
|
+
*
|
|
112
|
+
* @param model_dir Path to the model directory
|
|
113
|
+
* @param config Tokenizer configuration (source, custom URL, auto_download)
|
|
114
|
+
* @return RAC_SUCCESS if files exist or were downloaded successfully
|
|
115
|
+
* RAC_ERROR_FILE_NOT_FOUND if files missing and auto_download disabled
|
|
116
|
+
* RAC_ERROR_NETWORK if download failed
|
|
117
|
+
*
|
|
118
|
+
* Example:
|
|
119
|
+
* @code
|
|
120
|
+
* rac_diffusion_tokenizer_config_t config = {
|
|
121
|
+
* .source = RAC_DIFFUSION_TOKENIZER_SD_1_5,
|
|
122
|
+
* .custom_base_url = NULL,
|
|
123
|
+
* .auto_download = RAC_TRUE
|
|
124
|
+
* };
|
|
125
|
+
* rac_result_t result = rac_diffusion_tokenizer_ensure_files("/path/to/model", &config);
|
|
126
|
+
* @endcode
|
|
127
|
+
*/
|
|
128
|
+
RAC_API rac_result_t
|
|
129
|
+
rac_diffusion_tokenizer_ensure_files(const char* model_dir,
|
|
130
|
+
const rac_diffusion_tokenizer_config_t* config);
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* @brief Download a tokenizer file
|
|
134
|
+
*
|
|
135
|
+
* Downloads a specific tokenizer file from the configured source.
|
|
136
|
+
*
|
|
137
|
+
* @param source Tokenizer source preset
|
|
138
|
+
* @param custom_url Custom URL (only used when source == RAC_DIFFUSION_TOKENIZER_CUSTOM)
|
|
139
|
+
* @param filename File name to download (e.g., "vocab.json")
|
|
140
|
+
* @param output_path Full path where the file should be saved
|
|
141
|
+
* @return RAC_SUCCESS or error code
|
|
142
|
+
*/
|
|
143
|
+
RAC_API rac_result_t rac_diffusion_tokenizer_download_file(rac_diffusion_tokenizer_source_t source,
|
|
144
|
+
const char* custom_url,
|
|
145
|
+
const char* filename,
|
|
146
|
+
const char* output_path);
|
|
147
|
+
|
|
148
|
+
// =============================================================================
|
|
149
|
+
// DEFAULT TOKENIZER SOURCE FOR MODEL VARIANT
|
|
150
|
+
// =============================================================================
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* @brief Get the default tokenizer source for a model variant
|
|
154
|
+
*
|
|
155
|
+
* Returns the recommended tokenizer source for a given model variant.
|
|
156
|
+
*
|
|
157
|
+
* @param model_variant Model variant (SD 1.5, SD 2.1, SDXL, etc.)
|
|
158
|
+
* @return Default tokenizer source
|
|
159
|
+
*/
|
|
160
|
+
RAC_API rac_diffusion_tokenizer_source_t
|
|
161
|
+
rac_diffusion_tokenizer_default_for_variant(rac_diffusion_model_variant_t model_variant);
|
|
162
|
+
|
|
163
|
+
#ifdef __cplusplus
|
|
164
|
+
}
|
|
165
|
+
#endif
|
|
166
|
+
|
|
167
|
+
#endif /* RAC_DIFFUSION_TOKENIZER_H */
|
|
@@ -0,0 +1,454 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file rac_diffusion_types.h
|
|
3
|
+
* @brief RunAnywhere Commons - Diffusion Types and Data Structures
|
|
4
|
+
*
|
|
5
|
+
* This header defines data structures for image generation using diffusion models
|
|
6
|
+
* (Stable Diffusion). Supports text-to-image, image-to-image, and inpainting.
|
|
7
|
+
*
|
|
8
|
+
* This header defines data structures only. For the service interface,
|
|
9
|
+
* see rac_diffusion_service.h.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
#ifndef RAC_DIFFUSION_TYPES_H
|
|
13
|
+
#define RAC_DIFFUSION_TYPES_H
|
|
14
|
+
|
|
15
|
+
#include "rac/core/rac_types.h"
|
|
16
|
+
|
|
17
|
+
#ifdef __cplusplus
|
|
18
|
+
extern "C" {
|
|
19
|
+
#endif
|
|
20
|
+
|
|
21
|
+
// =============================================================================
|
|
22
|
+
// SCHEDULER TYPES
|
|
23
|
+
// =============================================================================
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* @brief Diffusion scheduler/sampler types
|
|
27
|
+
*
|
|
28
|
+
* Different scheduling algorithms for the denoising process.
|
|
29
|
+
* DPM++ 2M Karras is recommended for best quality/speed tradeoff.
|
|
30
|
+
*/
|
|
31
|
+
typedef enum rac_diffusion_scheduler {
|
|
32
|
+
RAC_DIFFUSION_SCHEDULER_DPM_PP_2M_KARRAS = 0, /**< DPM++ 2M Karras (recommended) */
|
|
33
|
+
RAC_DIFFUSION_SCHEDULER_DPM_PP_2M = 1, /**< DPM++ 2M */
|
|
34
|
+
RAC_DIFFUSION_SCHEDULER_DPM_PP_2M_SDE = 2, /**< DPM++ 2M SDE */
|
|
35
|
+
RAC_DIFFUSION_SCHEDULER_DDIM = 3, /**< DDIM */
|
|
36
|
+
RAC_DIFFUSION_SCHEDULER_EULER = 4, /**< Euler */
|
|
37
|
+
RAC_DIFFUSION_SCHEDULER_EULER_ANCESTRAL = 5, /**< Euler Ancestral */
|
|
38
|
+
RAC_DIFFUSION_SCHEDULER_PNDM = 6, /**< PNDM */
|
|
39
|
+
RAC_DIFFUSION_SCHEDULER_LMS = 7, /**< LMS */
|
|
40
|
+
} rac_diffusion_scheduler_t;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* @brief Model variant types
|
|
44
|
+
*
|
|
45
|
+
* Different Stable Diffusion model variants with different capabilities.
|
|
46
|
+
*/
|
|
47
|
+
typedef enum rac_diffusion_model_variant {
|
|
48
|
+
RAC_DIFFUSION_MODEL_SD_1_5 = 0, /**< Stable Diffusion 1.5 (512x512 default) */
|
|
49
|
+
RAC_DIFFUSION_MODEL_SD_2_1 = 1, /**< Stable Diffusion 2.1 (768x768 default) */
|
|
50
|
+
RAC_DIFFUSION_MODEL_SDXL = 2, /**< SDXL (1024x1024 default, requires 8GB+ RAM) */
|
|
51
|
+
RAC_DIFFUSION_MODEL_SDXL_TURBO = 3, /**< SDXL Turbo (fast, fewer steps, no CFG) */
|
|
52
|
+
RAC_DIFFUSION_MODEL_SDXS = 4, /**< SDXS - Ultra-fast 1-step model (no CFG) */
|
|
53
|
+
RAC_DIFFUSION_MODEL_LCM = 5, /**< LCM - Latent Consistency Model (4 steps) */
|
|
54
|
+
} rac_diffusion_model_variant_t;
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* @brief Generation mode
|
|
58
|
+
*/
|
|
59
|
+
typedef enum rac_diffusion_mode {
|
|
60
|
+
RAC_DIFFUSION_MODE_TEXT_TO_IMAGE = 0, /**< Generate image from text prompt */
|
|
61
|
+
RAC_DIFFUSION_MODE_IMAGE_TO_IMAGE = 1, /**< Transform input image with prompt */
|
|
62
|
+
RAC_DIFFUSION_MODE_INPAINTING = 2, /**< Edit specific regions with mask */
|
|
63
|
+
} rac_diffusion_mode_t;
|
|
64
|
+
|
|
65
|
+
// =============================================================================
|
|
66
|
+
// TOKENIZER CONFIGURATION
|
|
67
|
+
// =============================================================================
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* @brief Tokenizer source presets
|
|
71
|
+
*
|
|
72
|
+
* Predefined HuggingFace repository sources for tokenizer files.
|
|
73
|
+
* Apple's compiled CoreML models don't include tokenizer files (vocab.json, merges.txt),
|
|
74
|
+
* so they must be downloaded separately from HuggingFace.
|
|
75
|
+
*
|
|
76
|
+
* Developers can use RAC_DIFFUSION_TOKENIZER_CUSTOM with a custom_base_url
|
|
77
|
+
* to specify their own tokenizer source.
|
|
78
|
+
*/
|
|
79
|
+
typedef enum rac_diffusion_tokenizer_source {
|
|
80
|
+
/** Stable Diffusion 1.x tokenizer (CLIP ViT-L/14)
|
|
81
|
+
* Source: runwayml/stable-diffusion-v1-5 */
|
|
82
|
+
RAC_DIFFUSION_TOKENIZER_SD_1_5 = 0,
|
|
83
|
+
|
|
84
|
+
/** Stable Diffusion 2.x tokenizer (OpenCLIP ViT-H/14)
|
|
85
|
+
* Source: stabilityai/stable-diffusion-2-1 */
|
|
86
|
+
RAC_DIFFUSION_TOKENIZER_SD_2_X = 1,
|
|
87
|
+
|
|
88
|
+
/** Stable Diffusion XL tokenizer (dual tokenizers)
|
|
89
|
+
* Source: stabilityai/stable-diffusion-xl-base-1.0 */
|
|
90
|
+
RAC_DIFFUSION_TOKENIZER_SDXL = 2,
|
|
91
|
+
|
|
92
|
+
/** Custom tokenizer from a developer-specified URL
|
|
93
|
+
* Requires custom_base_url to be set in rac_diffusion_tokenizer_config_t */
|
|
94
|
+
RAC_DIFFUSION_TOKENIZER_CUSTOM = 99,
|
|
95
|
+
} rac_diffusion_tokenizer_source_t;
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* @brief Tokenizer configuration
|
|
99
|
+
*
|
|
100
|
+
* Configuration for downloading and using tokenizer files.
|
|
101
|
+
* The SDK will automatically download missing tokenizer files (vocab.json, merges.txt)
|
|
102
|
+
* from the specified source URL.
|
|
103
|
+
*
|
|
104
|
+
* Example for custom URL:
|
|
105
|
+
* @code
|
|
106
|
+
* rac_diffusion_tokenizer_config_t tokenizer_config = {
|
|
107
|
+
* .source = RAC_DIFFUSION_TOKENIZER_CUSTOM,
|
|
108
|
+
* .custom_base_url = "https://huggingface.co/my-org/my-model/resolve/main/tokenizer",
|
|
109
|
+
* .auto_download = RAC_TRUE
|
|
110
|
+
* };
|
|
111
|
+
* @endcode
|
|
112
|
+
*/
|
|
113
|
+
typedef struct rac_diffusion_tokenizer_config {
|
|
114
|
+
/** Tokenizer source preset (SD15, SD21, SDXL, or CUSTOM) */
|
|
115
|
+
rac_diffusion_tokenizer_source_t source;
|
|
116
|
+
|
|
117
|
+
/** Custom base URL for tokenizer files (only used when source == CUSTOM)
|
|
118
|
+
* Should be a URL directory containing vocab.json and merges.txt
|
|
119
|
+
* Example: "https://huggingface.co/my-org/my-model/resolve/main/tokenizer"
|
|
120
|
+
* The SDK will append "/vocab.json" and "/merges.txt" to download files */
|
|
121
|
+
const char* custom_base_url;
|
|
122
|
+
|
|
123
|
+
/** Automatically download missing tokenizer files (default: true) */
|
|
124
|
+
rac_bool_t auto_download;
|
|
125
|
+
} rac_diffusion_tokenizer_config_t;
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* @brief Default tokenizer configuration
|
|
129
|
+
*/
|
|
130
|
+
static const rac_diffusion_tokenizer_config_t RAC_DIFFUSION_TOKENIZER_CONFIG_DEFAULT = {
|
|
131
|
+
.source = RAC_DIFFUSION_TOKENIZER_SD_1_5,
|
|
132
|
+
.custom_base_url = RAC_NULL,
|
|
133
|
+
.auto_download = RAC_TRUE};
|
|
134
|
+
|
|
135
|
+
// =============================================================================
|
|
136
|
+
// CONFIGURATION - Component configuration
|
|
137
|
+
// =============================================================================
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* @brief Diffusion component configuration
|
|
141
|
+
*
|
|
142
|
+
* Configuration for initializing the diffusion component.
|
|
143
|
+
*/
|
|
144
|
+
typedef struct rac_diffusion_config {
|
|
145
|
+
/** Model ID (optional - uses default if NULL) */
|
|
146
|
+
const char* model_id;
|
|
147
|
+
|
|
148
|
+
/** Preferred framework (use RAC_FRAMEWORK_UNKNOWN for auto) */
|
|
149
|
+
int32_t preferred_framework;
|
|
150
|
+
|
|
151
|
+
/** Model variant (SD 1.5, SD 2.1, SDXL, etc.) */
|
|
152
|
+
rac_diffusion_model_variant_t model_variant;
|
|
153
|
+
|
|
154
|
+
/** Enable safety checker for NSFW content filtering (default: true) */
|
|
155
|
+
rac_bool_t enable_safety_checker;
|
|
156
|
+
|
|
157
|
+
/** Reduce memory footprint (may reduce quality, default: false) */
|
|
158
|
+
rac_bool_t reduce_memory;
|
|
159
|
+
|
|
160
|
+
/** Tokenizer configuration for downloading missing tokenizer files
|
|
161
|
+
* Apple's compiled CoreML models don't include tokenizer files */
|
|
162
|
+
rac_diffusion_tokenizer_config_t tokenizer;
|
|
163
|
+
} rac_diffusion_config_t;
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* @brief Default diffusion configuration
|
|
167
|
+
*/
|
|
168
|
+
static const rac_diffusion_config_t RAC_DIFFUSION_CONFIG_DEFAULT = {
|
|
169
|
+
.model_id = RAC_NULL,
|
|
170
|
+
.preferred_framework = 99, // RAC_FRAMEWORK_UNKNOWN
|
|
171
|
+
.model_variant = RAC_DIFFUSION_MODEL_SD_1_5,
|
|
172
|
+
.enable_safety_checker = RAC_TRUE,
|
|
173
|
+
.reduce_memory = RAC_FALSE,
|
|
174
|
+
.tokenizer = {.source = RAC_DIFFUSION_TOKENIZER_SD_1_5,
|
|
175
|
+
.custom_base_url = RAC_NULL,
|
|
176
|
+
.auto_download = RAC_TRUE}};
|
|
177
|
+
|
|
178
|
+
// =============================================================================
|
|
179
|
+
// OPTIONS - Generation options
|
|
180
|
+
// =============================================================================
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* @brief Diffusion generation options
|
|
184
|
+
*
|
|
185
|
+
* Options for controlling image generation.
|
|
186
|
+
*/
|
|
187
|
+
typedef struct rac_diffusion_options {
|
|
188
|
+
/** Text prompt describing the desired image */
|
|
189
|
+
const char* prompt;
|
|
190
|
+
|
|
191
|
+
/** Negative prompt - things to avoid in the image (can be NULL) */
|
|
192
|
+
const char* negative_prompt;
|
|
193
|
+
|
|
194
|
+
/** Output image width in pixels (default: 512 for SD 1.5, 1024 for SDXL) */
|
|
195
|
+
int32_t width;
|
|
196
|
+
|
|
197
|
+
/** Output image height in pixels (default: 512 for SD 1.5, 1024 for SDXL) */
|
|
198
|
+
int32_t height;
|
|
199
|
+
|
|
200
|
+
/** Number of denoising steps (default: 28, range: 10-50) */
|
|
201
|
+
int32_t steps;
|
|
202
|
+
|
|
203
|
+
/** Classifier-free guidance scale (default: 7.5, range: 1.0-20.0) */
|
|
204
|
+
float guidance_scale;
|
|
205
|
+
|
|
206
|
+
/** Random seed for reproducibility (-1 for random, default: -1) */
|
|
207
|
+
int64_t seed;
|
|
208
|
+
|
|
209
|
+
/** Scheduler/sampler algorithm (default: DPM++ 2M Karras) */
|
|
210
|
+
rac_diffusion_scheduler_t scheduler;
|
|
211
|
+
|
|
212
|
+
// --- Image-to-image / Inpainting options ---
|
|
213
|
+
|
|
214
|
+
/** Generation mode (text-to-image, img2img, inpainting) */
|
|
215
|
+
rac_diffusion_mode_t mode;
|
|
216
|
+
|
|
217
|
+
/** Input image RGBA data for img2img/inpainting (can be NULL) */
|
|
218
|
+
const uint8_t* input_image_data;
|
|
219
|
+
|
|
220
|
+
/** Input image data size in bytes */
|
|
221
|
+
size_t input_image_size;
|
|
222
|
+
|
|
223
|
+
/** Input image width (required if input_image_data is set) */
|
|
224
|
+
int32_t input_image_width;
|
|
225
|
+
|
|
226
|
+
/** Input image height (required if input_image_data is set) */
|
|
227
|
+
int32_t input_image_height;
|
|
228
|
+
|
|
229
|
+
/** Mask image data for inpainting - grayscale (can be NULL) */
|
|
230
|
+
const uint8_t* mask_data;
|
|
231
|
+
|
|
232
|
+
/** Mask data size in bytes */
|
|
233
|
+
size_t mask_size;
|
|
234
|
+
|
|
235
|
+
/** Denoising strength for img2img (0.0-1.0, default: 0.75) */
|
|
236
|
+
float denoise_strength;
|
|
237
|
+
|
|
238
|
+
// --- Progress reporting options ---
|
|
239
|
+
|
|
240
|
+
/** Report intermediate images during generation (default: false) */
|
|
241
|
+
rac_bool_t report_intermediate_images;
|
|
242
|
+
|
|
243
|
+
/** Report progress every N steps (default: 1) */
|
|
244
|
+
int32_t progress_stride;
|
|
245
|
+
} rac_diffusion_options_t;
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* @brief Default diffusion generation options
|
|
249
|
+
*/
|
|
250
|
+
static const rac_diffusion_options_t RAC_DIFFUSION_OPTIONS_DEFAULT = {
|
|
251
|
+
.prompt = RAC_NULL,
|
|
252
|
+
.negative_prompt = RAC_NULL,
|
|
253
|
+
.width = 512,
|
|
254
|
+
.height = 512,
|
|
255
|
+
.steps = 28,
|
|
256
|
+
.guidance_scale = 7.5f,
|
|
257
|
+
.seed = -1,
|
|
258
|
+
.scheduler = RAC_DIFFUSION_SCHEDULER_DPM_PP_2M_KARRAS,
|
|
259
|
+
.mode = RAC_DIFFUSION_MODE_TEXT_TO_IMAGE,
|
|
260
|
+
.input_image_data = RAC_NULL,
|
|
261
|
+
.input_image_size = 0,
|
|
262
|
+
.input_image_width = 0,
|
|
263
|
+
.input_image_height = 0,
|
|
264
|
+
.mask_data = RAC_NULL,
|
|
265
|
+
.mask_size = 0,
|
|
266
|
+
.denoise_strength = 0.75f,
|
|
267
|
+
.report_intermediate_images = RAC_FALSE,
|
|
268
|
+
.progress_stride = 1};
|
|
269
|
+
|
|
270
|
+
// =============================================================================
|
|
271
|
+
// PROGRESS - Generation progress
|
|
272
|
+
// =============================================================================
|
|
273
|
+
|
|
274
|
+
/**
|
|
275
|
+
* @brief Diffusion generation progress
|
|
276
|
+
*
|
|
277
|
+
* Reports progress during image generation.
|
|
278
|
+
*/
|
|
279
|
+
typedef struct rac_diffusion_progress {
|
|
280
|
+
/** Progress percentage (0.0 - 1.0) */
|
|
281
|
+
float progress;
|
|
282
|
+
|
|
283
|
+
/** Current step number (1-based) */
|
|
284
|
+
int32_t current_step;
|
|
285
|
+
|
|
286
|
+
/** Total number of steps */
|
|
287
|
+
int32_t total_steps;
|
|
288
|
+
|
|
289
|
+
/** Current stage description (e.g., "Encoding", "Denoising", "Decoding") */
|
|
290
|
+
const char* stage;
|
|
291
|
+
|
|
292
|
+
/** Intermediate image RGBA data (can be NULL if not requested) */
|
|
293
|
+
const uint8_t* intermediate_image_data;
|
|
294
|
+
|
|
295
|
+
/** Intermediate image data size */
|
|
296
|
+
size_t intermediate_image_size;
|
|
297
|
+
|
|
298
|
+
/** Intermediate image width */
|
|
299
|
+
int32_t intermediate_image_width;
|
|
300
|
+
|
|
301
|
+
/** Intermediate image height */
|
|
302
|
+
int32_t intermediate_image_height;
|
|
303
|
+
} rac_diffusion_progress_t;
|
|
304
|
+
|
|
305
|
+
// =============================================================================
|
|
306
|
+
// RESULT - Generation result
|
|
307
|
+
// =============================================================================
|
|
308
|
+
|
|
309
|
+
/**
|
|
310
|
+
* @brief Diffusion generation result
|
|
311
|
+
*
|
|
312
|
+
* Contains the generated image and metadata.
|
|
313
|
+
*/
|
|
314
|
+
typedef struct rac_diffusion_result {
|
|
315
|
+
/** Generated image RGBA data (owned, must be freed with rac_diffusion_result_free) */
|
|
316
|
+
uint8_t* image_data;
|
|
317
|
+
|
|
318
|
+
/** Image data size in bytes */
|
|
319
|
+
size_t image_size;
|
|
320
|
+
|
|
321
|
+
/** Image width in pixels */
|
|
322
|
+
int32_t width;
|
|
323
|
+
|
|
324
|
+
/** Image height in pixels */
|
|
325
|
+
int32_t height;
|
|
326
|
+
|
|
327
|
+
/** Seed used for generation (useful for reproducibility) */
|
|
328
|
+
int64_t seed_used;
|
|
329
|
+
|
|
330
|
+
/** Total generation time in milliseconds */
|
|
331
|
+
int64_t generation_time_ms;
|
|
332
|
+
|
|
333
|
+
/** Whether the image was flagged by safety checker */
|
|
334
|
+
rac_bool_t safety_flagged;
|
|
335
|
+
|
|
336
|
+
/** Error code if generation failed (RAC_SUCCESS on success) */
|
|
337
|
+
rac_result_t error_code;
|
|
338
|
+
|
|
339
|
+
/** Error message if generation failed (can be NULL) */
|
|
340
|
+
char* error_message;
|
|
341
|
+
} rac_diffusion_result_t;
|
|
342
|
+
|
|
343
|
+
// =============================================================================
|
|
344
|
+
// INFO - Service information
|
|
345
|
+
// =============================================================================
|
|
346
|
+
|
|
347
|
+
/**
|
|
348
|
+
* @brief Diffusion service information
|
|
349
|
+
*
|
|
350
|
+
* Information about the loaded diffusion service.
|
|
351
|
+
*/
|
|
352
|
+
typedef struct rac_diffusion_info {
|
|
353
|
+
/** Whether the service is ready for generation */
|
|
354
|
+
rac_bool_t is_ready;
|
|
355
|
+
|
|
356
|
+
/** Current model identifier (can be NULL) */
|
|
357
|
+
const char* current_model;
|
|
358
|
+
|
|
359
|
+
/** Model variant */
|
|
360
|
+
rac_diffusion_model_variant_t model_variant;
|
|
361
|
+
|
|
362
|
+
/** Whether text-to-image is supported */
|
|
363
|
+
rac_bool_t supports_text_to_image;
|
|
364
|
+
|
|
365
|
+
/** Whether image-to-image is supported */
|
|
366
|
+
rac_bool_t supports_image_to_image;
|
|
367
|
+
|
|
368
|
+
/** Whether inpainting is supported */
|
|
369
|
+
rac_bool_t supports_inpainting;
|
|
370
|
+
|
|
371
|
+
/** Whether safety checker is enabled */
|
|
372
|
+
rac_bool_t safety_checker_enabled;
|
|
373
|
+
|
|
374
|
+
/** Maximum supported width */
|
|
375
|
+
int32_t max_width;
|
|
376
|
+
|
|
377
|
+
/** Maximum supported height */
|
|
378
|
+
int32_t max_height;
|
|
379
|
+
} rac_diffusion_info_t;
|
|
380
|
+
|
|
381
|
+
// =============================================================================
|
|
382
|
+
// CALLBACKS
|
|
383
|
+
// =============================================================================
|
|
384
|
+
|
|
385
|
+
/**
|
|
386
|
+
* @brief Diffusion progress callback
|
|
387
|
+
*
|
|
388
|
+
* Called during generation to report progress.
|
|
389
|
+
*
|
|
390
|
+
* @param progress Progress information
|
|
391
|
+
* @param user_data User-provided context
|
|
392
|
+
* @return RAC_TRUE to continue, RAC_FALSE to cancel generation
|
|
393
|
+
*/
|
|
394
|
+
typedef rac_bool_t (*rac_diffusion_progress_callback_fn)(const rac_diffusion_progress_t* progress,
|
|
395
|
+
void* user_data);
|
|
396
|
+
|
|
397
|
+
/**
|
|
398
|
+
* @brief Diffusion completion callback
|
|
399
|
+
*
|
|
400
|
+
* Called when generation completes successfully.
|
|
401
|
+
*
|
|
402
|
+
* @param result Generation result
|
|
403
|
+
* @param user_data User-provided context
|
|
404
|
+
*/
|
|
405
|
+
typedef void (*rac_diffusion_complete_callback_fn)(const rac_diffusion_result_t* result,
|
|
406
|
+
void* user_data);
|
|
407
|
+
|
|
408
|
+
/**
|
|
409
|
+
* @brief Diffusion error callback
|
|
410
|
+
*
|
|
411
|
+
* Called when generation fails.
|
|
412
|
+
*
|
|
413
|
+
* @param error_code Error code
|
|
414
|
+
* @param error_message Error message
|
|
415
|
+
* @param user_data User-provided context
|
|
416
|
+
*/
|
|
417
|
+
typedef void (*rac_diffusion_error_callback_fn)(rac_result_t error_code, const char* error_message,
|
|
418
|
+
void* user_data);
|
|
419
|
+
|
|
420
|
+
// =============================================================================
|
|
421
|
+
// CAPABILITY FLAGS
|
|
422
|
+
// =============================================================================
|
|
423
|
+
|
|
424
|
+
/** Supports text-to-image generation */
|
|
425
|
+
#define RAC_DIFFUSION_CAP_TEXT_TO_IMAGE (1 << 0)
|
|
426
|
+
|
|
427
|
+
/** Supports image-to-image transformation */
|
|
428
|
+
#define RAC_DIFFUSION_CAP_IMAGE_TO_IMAGE (1 << 1)
|
|
429
|
+
|
|
430
|
+
/** Supports inpainting with mask */
|
|
431
|
+
#define RAC_DIFFUSION_CAP_INPAINTING (1 << 2)
|
|
432
|
+
|
|
433
|
+
/** Supports intermediate image reporting */
|
|
434
|
+
#define RAC_DIFFUSION_CAP_INTERMEDIATE_IMAGES (1 << 3)
|
|
435
|
+
|
|
436
|
+
/** Has safety checker */
|
|
437
|
+
#define RAC_DIFFUSION_CAP_SAFETY_CHECKER (1 << 4)
|
|
438
|
+
|
|
439
|
+
// =============================================================================
|
|
440
|
+
// MEMORY MANAGEMENT
|
|
441
|
+
// =============================================================================
|
|
442
|
+
|
|
443
|
+
/**
|
|
444
|
+
* @brief Free diffusion result resources
|
|
445
|
+
*
|
|
446
|
+
* @param result Result to free (can be NULL)
|
|
447
|
+
*/
|
|
448
|
+
RAC_API void rac_diffusion_result_free(rac_diffusion_result_t* result);
|
|
449
|
+
|
|
450
|
+
#ifdef __cplusplus
|
|
451
|
+
}
|
|
452
|
+
#endif
|
|
453
|
+
|
|
454
|
+
#endif /* RAC_DIFFUSION_TYPES_H */
|