Instructions to use marketeam/Fineweb-Classifier-Marketing with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use marketeam/Fineweb-Classifier-Marketing with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-classification", model="marketeam/Fineweb-Classifier-Marketing", trust_remote_code=True)# Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("marketeam/Fineweb-Classifier-Marketing", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
Fix meta-device crash on newer transformers; document required transformers==4.46.3
Browse filesmodeling_marketing_classifier.py: build the encoder via AutoModel.from_config() instead of AutoModel.from_pretrained() inside __init__. The nested from_pretrained call conflicted with the meta-device/low_cpu_mem_usage context that the outer PreTrainedModel.from_pretrained() wraps __init__ in on transformers>=5, causing 'You are using from_pretrained with a meta device context manager' errors (reported from a fresh Colab install). from_config is meta-safe and behaves identically here since the real encoder weights are always supplied by this class's own checkpoint, not downloaded separately -- verified byte-identical output vs the original MarketingClassifier class before and after this change.
Separately, transformers>=5 is not usable with this model regardless of the above fix: the frozen encoder's own custom code (Snowflake/snowflake-arctic-embed-m-v2.0's modeling_hf_alibaba_nlp_gte.py, not ours) hits an IndexError in its RoPE position_ids handling under transformers 5.x. README now states the transformers==4.46.3 requirement explicitly in How to Use.
- README.md +2 -0
- modeling_marketing_classifier.py +9 -3
|
@@ -144,6 +144,8 @@ Only BMse is recommended for production. Others are retained for reproducibility
|
|
| 144 |
|
| 145 |
## How to Use
|
| 146 |
|
|
|
|
|
|
|
| 147 |
### Pipeline (recommended)
|
| 148 |
|
| 149 |
```python
|
|
|
|
| 144 |
|
| 145 |
## How to Use
|
| 146 |
|
| 147 |
+
All usage paths below require `transformers` in the 4.46.x line (the frozen encoder's own custom code is not compatible with `transformers` 5.x): `pip install "transformers==4.46.3"`.
|
| 148 |
+
|
| 149 |
### Pipeline (recommended)
|
| 150 |
|
| 151 |
```python
|
|
@@ -23,9 +23,15 @@ class MarketingClassifierForRegression(PreTrainedModel):
|
|
| 23 |
|
| 24 |
encoder_config = AutoConfig.from_pretrained(config.backbone, trust_remote_code=True)
|
| 25 |
encoder_config.use_memory_efficient_attention = False
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
add_pooling_layer=False,
|
| 30 |
trust_remote_code=True,
|
| 31 |
attn_implementation="sdpa",
|
|
|
|
| 23 |
|
| 24 |
encoder_config = AutoConfig.from_pretrained(config.backbone, trust_remote_code=True)
|
| 25 |
encoder_config.use_memory_efficient_attention = False
|
| 26 |
+
# Build the encoder architecture only (random weights, meta-device safe) --
|
| 27 |
+
# do NOT call AutoModel.from_pretrained() here. This class's own weights
|
| 28 |
+
# (loaded by the outer from_pretrained() call, which already contains the
|
| 29 |
+
# full encoder + head state dict) are what actually populate `self.encoder`.
|
| 30 |
+
# A nested from_pretrained() call here conflicts with the meta-device /
|
| 31 |
+
# low_cpu_mem_usage context that from_pretrained wraps __init__ in on
|
| 32 |
+
# newer transformers versions.
|
| 33 |
+
self.encoder = AutoModel.from_config(
|
| 34 |
+
encoder_config,
|
| 35 |
add_pooling_layer=False,
|
| 36 |
trust_remote_code=True,
|
| 37 |
attn_implementation="sdpa",
|